Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class HowHealthy
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. String name;
  9. String printGender;
  10. //creates new scanner class
  11. Scanner scan = new Scanner(System.in);
  12.  
  13. Healthy person = new Healthy();
  14. //takes in String name with validation
  15. boolean valid = true;
  16. do
  17. {
  18. System.out.print("\nPerson's name: ");
  19. name = scan.nextLine();
  20.  
  21. valid = person.setName(name);
  22. if (!valid)
  23. {
  24. System.out.println("Invalid Name - must have at least one character");
  25. }
  26.  
  27. }//do
  28. while (!valid);
  29.  
  30.  
  31. //takes in gender with validation
  32. System.out.print(name + ", are you male or female (M/F)? ");
  33. String gender = scan.nextLine();
  34. //takes in weight
  35. System.out.print(name + "'s weight (pounds): ");
  36. double pounds = scan.nextDouble();
  37. if (pounds < 100)
  38. {
  39. System.out.println("Invalid weight - must be at least 100 pounds.");
  40. System.exit(1);
  41. }
  42.  
  43. //takes in height with validation
  44. System.out.print(name + "'s height (inches): ");
  45. double inches = scan.nextDouble();
  46. if (inches >= 85 || inches <= 59)
  47.  
  48. {
  49. System.out.println("Invalid height - must be between 60 and 84 inches inclusively.");
  50. System.exit(1);
  51. }
  52.  
  53. //takes in age with validation
  54. System.out.print(name + "'s age (years): ");
  55. int age = scan.nextInt();
  56. if (age < 18)
  57. {
  58. System.out.println("Invalid age - must be at least 18 years old.");
  59. System.exit(1);
  60. }
  61.  
  62. //prints all activity levels
  63. System.out.println("Activity Level: Use these categories:");
  64. System.out.println("\t1 - Sedentary (little or no exercise, desk job)");
  65. System.out.println("\t2 - Lightly active (light exercise/sports 1-3 days/wk)");
  66. System.out.println("\t3 - Moderately active (moderate exercise/sports 3-5 days/wk)");
  67. System.out.println("\t4 - Very active (hard exercise/sports 6-7 days/wk)");
  68. System.out.println("\t5 - Extra active (hard daily exercise/sports & physical job or\n\t\t 2X day training i.e marathon, contest etc.)");
  69. //takes in activity level with validation
  70. System.out.print("How active are you? ");
  71. int actLevel = scan.nextInt();
  72. if (actLevel < 1 || actLevel > 5)
  73.  
  74. {
  75. System.out.println("Invalid activity level - must be between 1 and 5 inclusively");
  76. System.exit(1);
  77. }
  78.  
  79. //creates new Healthy object named david
  80. Healthy david = new Healthy();
  81. //prints all inputed information
  82. System.out.println(david.getName() + "'s information");
  83. System.out.println("Weight: " + david.getWeight() + " pounds");
  84. System.out.println("Height: " + david.getHeight() + " inches");
  85. System.out.println("Age: " + david.getAge() + " years");
  86.  
  87. //determines if input is for a male or female
  88. if (gender.equalsIgnoreCase("M"))
  89. printGender = "Male";
  90. else
  91. printGender = "Female";
  92.  
  93. //prints gender, bmr, bmi, and tdee
  94. System.out.println("These are for a " + printGender + ".");
  95. System.out.println("");
  96. System.out.printf("BMR is %.2f\n", david.calcBmr());
  97. System.out.printf("BMI is %.2f\n", david.calcBmi());
  98. System.out.printf("TDEE is %.2f\n\n", david.calcTdee());
  99. System.out.println(david.calcStatus());
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. }//main
  113.  
  114.  
  115.  
  116. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement