Advertisement
Guest User

Untitled

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