Assignment 38; InterplanetaryTravel
Code
// Donovan Rich
// Period 6
// Space Boxing
// InterplanetaryTravel.java
// 10/19/2015
import java.util.Scanner;
public class InterplanetaryTravel {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int planet;
double earthWeight, fixWeight;
String unit, planetName;
System.out.print ( "Please enter your weight on Earth, sir. " );
earthWeight = keyboard.nextDouble();
System.out.print ( "And what unit is that measurement in? " );
unit = keyboard.next();
System.out.println ( "Very good. The following planets are available for weight conversion." );
System.out.println ( "| ID#2: 'Venus' | ID #17: 'Mars' | ID #36: 'Saturn' |" );
System.out.println ( "| ID#134: 'Uranus' | ID #157: 'Neptune' | ID #974: 'Jupiter' |" );
System.out.println ( "|___________________________________________________________________|" );
System.out.println ();
System.out.print ( "Planet ID: #" );
planet = keyboard.nextInt();
if ( planet == 2 )
{
fixWeight = earthWeight * 0.78;
planetName = "Venus";
}
else if ( planet == 17 )
{
fixWeight = earthWeight * 0.39;
planetName = "Mars";
}
else if ( planet == 36 )
{
fixWeight = earthWeight * 1.17;
planetName = "Saturn";
}
else if ( planet == 134 )
{
fixWeight = earthWeight * 1.05;
planetName = "Uranus";
}
else if ( planet == 157 )
{
fixWeight = earthWeight * 1.23;
planetName = "Neptune";
}
else if ( planet == 974 )
{
fixWeight = earthWeight * 2.65;
planetName = "Jupiter";
}
else
{
fixWeight = 404;
unit = "*ERROR*";
planetName = "INVALID_INPUT";
}
System.out.println ( "On " + planetName + ", you weigh " + fixWeight + " " + unit + "." );
}
}
Picture of the output