Advertisement
Guest User

Untitled

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