Advertisement
Guest User

Untitled

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