-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBMICalculator.java
More file actions
132 lines (120 loc) · 4.15 KB
/
BMICalculator.java
File metadata and controls
132 lines (120 loc) · 4.15 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Lab Assignment - 2
ID: U1910060
Name: Alimov Abdullokh
Section: 002
*/
import java.util.Scanner;
public class BMIu1910060
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); //Object for Scanner
double height, weight;
boolean option = true;
int menu;
float BMI;
int repitation;
while(option) // Loop for Menu
{
System.out.println(" -- Menu -- ");
System.out.println("1. Calculate in (kg and meters)");
System.out.println("2. Calculate in (ib and inches)");
System.out.print("Enter Choice: ");
menu = (input.nextInt()); // menu choice to use switch cases
switch(menu)
{
case 1: // Case for calculating BMI in (kg and m)
{
System.out.print("Height (meters): ");
height = (input.nextDouble()); // getting height from user
while (height <= 0){ // Validation for height
System.out.print("Height (meters): ");
height = (input.nextDouble()); // getting height again from user
}
System.out.print("Weight (kg): ");
weight = input.nextDouble(); // getting weight from user
while (weight <= 0){ // Validation for weight
System.out.print("Weight (kg): ");
weight = input.nextDouble(); // getting weight again from user
}
BMI = (float) (weight/(height*height)); // calculatin BMI and making it
System.out.println("----------------------");
/* Conditions to print BMI with its description */
if (BMI < 18.5){
System.out.printf("BMI is %.2f Underweight", BMI);
}
else if (BMI >= 18.5 && BMI<=24.9){
System.out.printf("BMI is %.2f Normal ", BMI);
}
else if (BMI >= 25 && BMI<=29.9){
System.out.printf("BMI is %.2f Overweight", BMI);
}
else if (BMI >= 30 && BMI<=34.9){
System.out.printf("BMI is %.2f Obese", BMI);
}
else {
System.out.printf("BMI is %.2f Extremely Obese", BMI);
}
// Condition for calculation repitation
System.out.println("");
System.out.println("----------------------");
System.out.println("Enter 1 for Calculating again");
System.out.println("Enter any number for Exit");
repitation = input.nextInt();
if (repitation != 1){
option = false;
}
}
break;
case 2: // Case for calculating BMI in (ib and in)
{
System.out.print("Height (inches): ");
height = (input.nextDouble()); // getting height from user
// Validation for height
while (height <= 0){
System.out.print("Height (inches): ");
height = (input.nextDouble()); // getting height again from user
}
System.out.print("Weight (ib): ");
weight = input.nextDouble(); // getting weight from user
// Validation for weight
while (weight <= 0){
System.out.print("Weight (ib): ");
weight = input.nextDouble(); // getting weight again from user
}
BMI = (float) ((weight/(height*height))*703); // calculatin BMI and making it
System.out.println("----------------------");
/* Conditions to print BMI with its description */
if (BMI < 18.5){
System.out.printf("BMI is %.2f Underweight", BMI);
}
else if (BMI >= 18.5 && BMI<=24.9){
System.out.printf("BMI is %.2f Normal ", BMI);
}
else if (BMI >= 25 && BMI<=29.9){
System.out.printf("BMI is %.2f Overweight", BMI);
}
else if (BMI >= 30 && BMI<=34.9){
System.out.printf("BMI is %.2f Obese", BMI);
}
else {
System.out.printf("BMI is %.2f Extremely Obese", BMI);
}
// Condition for calculation repitation
System.out.println("");
System.out.println("----------------------");
System.out.println("Enter 1 for Calculating again");
System.out.println("Enter any number for Exit");
repitation = input.nextInt();
if (repitation != 1){
option = false;
}
}
break;
default:
System.out.println("Menu does not contains that number, Please enter again");
}
}
}
}