Skip to content

Commit ab10ad7

Browse files
committed
BMI interpreter
1 parent 1f8bfe2 commit ab10ad7

File tree

11 files changed

+213
-0
lines changed

11 files changed

+213
-0
lines changed

week-03/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

week-03/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

week-03/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

week-03/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
2.52 KB
Binary file not shown.
2.16 KB
Binary file not shown.

week-03/src/App.class

2.23 KB
Binary file not shown.

week-03/src/App.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* Student: Rustam Zokirov
2+
ID: U1910049
3+
Lab: #2 BMI Calculator
4+
*/
5+
import java.util.Scanner; // Import the Scanner class
6+
7+
public class App { // Create a Class App
8+
public static void main(String[] args){
9+
Scanner input = new Scanner(System.in); // Create a scanner object
10+
int choice;
11+
boolean isCalculate = true;
12+
float height = 0, weight = 0, BMI;
13+
int choice2;
14+
15+
while(isCalculate) {
16+
System.out.println("*** Welcome to BMI Calculator! ***");
17+
System.out.println("Please enter only numbers!\n" + "1. Kilograms and meters\n" + "2. Pounds and inches\n" + "0. Exit\n" + "Choose option: ");
18+
choice = input.nextInt();
19+
20+
switch (choice) {
21+
case 0: {
22+
isCalculate = false;
23+
}break;
24+
case 1: { // Kilograms and meters
25+
for (int i = 0; i == 0; ) { //taking data from user and check for validation
26+
System.out.println("Enter height (meters): ");
27+
height = input.nextFloat();
28+
System.out.println("Enter weight (kg): ");
29+
weight = input.nextFloat();
30+
31+
if (height > 0 && weight > 0)
32+
i = 1;
33+
else
34+
System.out.println("Enter correct values!");
35+
36+
}
37+
38+
BMI = weight / (height * height);
39+
40+
if (BMI < 18.5)
41+
System.out.printf("BMI: %.2f Underweight", BMI);
42+
else if (BMI >= 18.5 && BMI < 25)
43+
System.out.printf("BMI: %.2f Normal", BMI);
44+
else if (BMI >= 25 && BMI < 30)
45+
System.out.printf("BMI: %.2f Overweight", BMI);
46+
else if (BMI >= 30 && BMI < 35)
47+
System.out.printf("BMI: %.2f Obese", BMI);
48+
else
49+
System.out.printf("BMI: %.2f Extremely Obese", BMI);
50+
51+
System.out.println("\nDo you want to calculate again? (1. YES / Any key. NO)");
52+
choice2 = input.nextInt();
53+
54+
if (choice2 != 1)
55+
isCalculate = false;
56+
57+
}break;
58+
case 2: { // Pounds and inches
59+
for (int i = 0; i == 0; ) { //taking data from user and check for validation
60+
System.out.println("Enter height (inches): ");
61+
height = input.nextFloat();
62+
System.out.println("Enter weight (pounds): ");
63+
weight = input.nextFloat();
64+
65+
if (height > 0 && weight > 0)
66+
i = 1;
67+
else
68+
System.out.println("Enter correct values!");
69+
70+
}
71+
72+
BMI = 703 * weight / (height * height);
73+
74+
if (BMI < 18.5)
75+
System.out.printf("BMI: %.2f Underweight", BMI);
76+
else if (BMI >= 18.5 && BMI < 25)
77+
System.out.printf("BMI: %.2f Normal", BMI);
78+
else if (BMI >= 25 && BMI <= 30)
79+
System.out.printf("BMI: %.2f Overweight", BMI);
80+
else if (BMI >= 30 && BMI <= 35)
81+
System.out.printf("BMI: %.2f Obese", BMI);
82+
else
83+
System.out.printf("BMI: %.2f Extremely Obese", BMI);
84+
85+
System.out.println("\nDo you want to calculate again? (1. YES / 0. NO) ");
86+
choice2 = input.nextInt();
87+
88+
if (choice2 != 1)
89+
isCalculate = false;
90+
91+
}break;
92+
default: {
93+
System.out.println("Please enter correct values!");
94+
}break;
95+
} // switch
96+
97+
} //while
98+
99+
} // main()
100+
101+
} // Class App

week-03/src/App2.class

1.85 KB
Binary file not shown.

week-03/src/App2.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Student: Rustam Zokirov
2+
ID: U1910049
3+
Lab: #2 BMI Calculator
4+
*/
5+
import java.util.Scanner; // Import the Scanner class
6+
7+
public class App2 { // Create a Class App
8+
public static void calculate(int choice){
9+
boolean isCalculate = true;
10+
float height = 0, weight = 0, BMI; // declaring some variables
11+
int choice2;
12+
13+
while(isCalculate) {
14+
Scanner input = new Scanner(System.in); // Create a scanner object
15+
16+
for (int i = 0; i == 0; ) { //taking data from user and check for validation
17+
System.out.println("Enter height: ");
18+
height = input.nextFloat(); // read height input
19+
System.out.println("Enter weight: ");
20+
weight = input.nextFloat(); // read weight input
21+
22+
if (height > 0 && weight > 0) // validate for >0
23+
i = 1;
24+
else
25+
System.out.println("Enter correct values!");
26+
}
27+
28+
if (choice == 1) { // for kg
29+
BMI = weight / (height * height);
30+
}
31+
else { // for pounds
32+
BMI = 703 * weight / (height * height);
33+
}
34+
35+
if (BMI < 18.5)
36+
System.out.printf("BMI: %.2f Underweight", BMI);
37+
else if (BMI >= 18.5 && BMI < 25)
38+
System.out.printf("BMI: %.2f Normal", BMI);
39+
else if (BMI >= 25 && BMI < 30)
40+
System.out.printf("BMI: %.2f Overweight", BMI);
41+
else if (BMI >= 30 && BMI < 35)
42+
System.out.printf("BMI: %.2f Obese", BMI);
43+
else
44+
System.out.printf("BMI: %.2f Extremely Obese", BMI);
45+
46+
System.out.println("\nDo you want to calculate again? (1. YES / Any key. NO) ");
47+
choice2 = input.nextInt(); // read the input
48+
49+
if (choice2 != 1)
50+
isCalculate = false; // exit from the loop
51+
}
52+
53+
}
54+
55+
public static void main(String[] args){
56+
Scanner input = new Scanner(System.in); // Create a scanner object
57+
int choice;
58+
59+
System.out.println("*** Welcome to BMI Calculator! ***");
60+
System.out.println("Please enter only numbers!\n" + "1. Kilograms and meters\n" + "2. Pounds and inches\n" + "0. Exit\n" + "Choose option: ");
61+
choice = input.nextInt();
62+
63+
switch (choice) { // switch for the menu
64+
case 0: { // Pounds and inches
65+
System.exit(0); //
66+
}break;
67+
case 1: { // Kilograms and meters
68+
calculate(1);
69+
}break;
70+
case 2: { // Pounds and inches
71+
calculate(2);
72+
}break;
73+
default:{
74+
System.out.println("Invalid input!");
75+
}break;
76+
} // switch
77+
} // main()
78+
} // Class App

0 commit comments

Comments
 (0)