Daryan997

OOP - HW 1

Nov 28th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package bmi_calculator;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class BMI_Calculator {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. System.out.println("*************** Healthy Life ***************\n"
  10. + "1--> Start\n"
  11. + "0--> Exit\n"
  12. + "-------------------------");
  13. System.out.print("Enter your choice: ");
  14. int choice = scanner.nextInt();
  15. while (choice != 0) {
  16. if (choice == 1) {
  17. System.out.print("Enter weight: ");
  18. int weight = scanner.nextInt();
  19. System.out.print("Enter height: ");
  20. double height = scanner.nextDouble();
  21. int bmi = (int) (weight / (height * height));
  22. System.out.println("BMI is --> " + bmi);
  23. if (bmi < 18.5) {
  24. System.out.println("You are underweight!");
  25. } else if (bmi >= 18.5 && bmi <= 24.9) {
  26. System.out.println("You have normal weight");
  27. } else if (bmi >= 25 && bmi <= 29.9) {
  28. System.out.println("You are overweight");
  29. } else {
  30. System.out.println("You are obesity");
  31. }
  32. } else {
  33. System.out.println("Invalid choice.");
  34. }
  35. System.out.println("****************************");
  36. System.out.println("Do you want to Continue?\n"
  37. + "1--> Continue\n"
  38. + "0--> Exit\n"
  39. + "-------------------------");
  40. System.out.print("Enter your choice: ");
  41. choice = scanner.nextInt();
  42. }
  43. System.out.println("Good Bye");
  44. }
  45.  
  46. }
  47.  
Add Comment
Please, Sign In to add comment