Skip to content

Instantly share code, notes, and snippets.

@grahammitchell
Created February 28, 2013 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahammitchell/5058677 to your computer and use it in GitHub Desktop.
Save grahammitchell/5058677 to your computer and use it in GitHub Desktop.
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." );
}
}
}
@simplemagik
Copy link

man, have your heared about switch operator?

@grahammitchell
Copy link
Author

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.

@sumtyme
Copy link

sumtyme commented Feb 28, 2013

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