Created
February 28, 2013 17:51
-
-
Save grahammitchell/5058677 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class SpaceBoxing | |
{ | |
public static void main( String[] args ) | |
{ | |
Scanner keyboard = new Scanner(System.in); | |
double weight; | |
int whichplanet; | |
System.out.print( "Please enter your current earth weight: " ); | |
weight = keyboard.nextDouble(); | |
System.out.println(); | |
System.out.println( "I have information for the following planets:" ); | |
System.out.println( "\t1. Venus 2. Mars 3. Jupiter" ); | |
System.out.println( "\t4. Saturn 5. Uranus 6. Neptune" ); | |
System.out.print( "Which planet are you visiting? " ); | |
whichplanet = keyboard.nextInt(); | |
if ( whichplanet == 1 ) | |
{ | |
System.out.println( "Your weight would be " + weight * 0.78 + " on that planet." ); | |
} | |
if ( whichplanet == 2 ) | |
{ | |
System.out.println( "Your weight would be " + weight * 0.39 + " on that planet." ); | |
} | |
if ( whichplanet == 3 ) | |
{ | |
System.out.println( "Your weight would be " + weight * 2.65 + " on that planet." ); | |
} | |
if ( whichplanet == 4 ) | |
{ | |
System.out.println( "Your weight would be " + weight * 1.17 + " on that planet." ); | |
} | |
if ( whichplanet == 5 ) | |
{ | |
System.out.println( "Your weight would be " + weight * 1.05 + " on that planet." ); | |
} | |
if ( whichplanet == 6 ) | |
{ | |
System.out.println( "Your weight would be " + weight * 1.23 + " on that planet." ); | |
} | |
} | |
} |
Have you introduced associative arrays / maps by this point?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have. But my students haven't, and this assignment is designed for them.
Also, a switch wouldn't make this code any better, just different.