-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMassCalc.java
60 lines (56 loc) · 1.45 KB
/
MassCalc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("What planet are you on?");
String planet = scan.nextLine().toLowerCase();
System.out.println("What is your mass on earth, in kilograms?");
double mass = scan.nextInt();
calculateMass(planet, mass);
}
public static void calculateMass(String planet, double mass) {
String returnState = "";
int flag = 0;
double weight = mass;
switch(planet) {
case "mercury" :
weight = mass * 3.59;
break;
case "venus" :
weight = mass * 8.87;
break;
case "earth" :
weight = mass * 9.81;
break;
case "moon" :
weight = mass * 1.62;
break;
case "mars" :
weight = mass * 3.77;
break;
case "jupiter" :
weight = mass * 25.95;
break;
case "saturn" :
weight = mass * 11.08;
break;
case "uranus" :
weight = mass * 10.67;
break;
case "neptune" :
weight = mass * 14.07;
break;
case "pluto" :
weight = mass * 0.42;
break;
default :
returnState = "Error: Planet not found. Please try again.";
flag = 1;
break;
}
if(flag != 1) {
returnState = "Your weight on " + planet + " is " + weight + "Newtons.";
}
System.out.print(returnState);
}
}