-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
66 lines (53 loc) · 3.09 KB
/
Main.java
File metadata and controls
66 lines (53 loc) · 3.09 KB
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
59
60
61
62
63
64
65
66
public class Main {
public static void main(String[] args) {
// Variables to store the weight and height values
double weight , height;
// Variable to hold the BMI value
double bmi = 0;
// Variable to hold the BMI system value obtained from user input
String bmiSystem;
// Variable to hold the BMI category determined by this BMI Calculator
String bmiCategory;
// Please initialize this reference variable to create an object of the UserInput class
UserInput userInput = new UserInput();
// Please initialize this reference variable to create an object of the BMICalculator class
BMICalculator bmiCalculator = new BMICalculator();
// Invoke the obtainBMISystem() of the UserInput class
bmiSystem = userInput.obtainBMISystem();
// A Switch statement that determines how user input for weight and height should be obtained based on the BMI system
switch (bmiSystem.toUpperCase()) {
// The case of IMPERIAL BMI system
case "IMPERIAL":
weight = userInput.obtainWeight(bmiSystem);
height = userInput.obtainHeight(bmiSystem);
bmi = bmiCalculator.calculateBmiImperial(weight , height);
// Please invoke the obtainWeight() method of the UserInput class and assign it to the variable weight
// Please invoke the obtainHeight() method of the UserInput class and assign it to the variable height
// Please invoke the calculateBmiImperial() method of the BMICalculator class
// Break out of the switch statement
break;
// The case of METRIC BMI system
case "METRIC":
weight = userInput.obtainWeight(bmiSystem);
height = userInput.obtainHeight(bmiSystem);
bmi = bmiCalculator.calculateBmiMetric(weight , height);
// Please invoke the obtainWeight() method of the UserInput class and assign it to the variable weight
// Please invoke the obtainHeight() method of the UserInput class and assign it to the variable height
// Please invoke the calculateBmiMetric() method of the BMICalculator class
// Break out of the switch statement
break;
// The case of empty BMI system due to invalid user input
case "":
// Please display a message asking the user to enter a valid BMI system in case of invalid input
System.out.println("Please Enter a valid BMI System as input");
// Break out of the switch statement
break;
}
// Display the calculated BMI value to the user
System.out.println("Your BMI is: " + bmi);
bmiCategory = bmiCalculator.getBMICategory(bmi);
// Please invoke the getBMICategory() method of the BMICalculator class and assign the result to the bmiCategory variable
// Display the BMI category to the user
System.out.println("Your BMI category is: " + bmiCategory);
}
}