Advertisement
Guest User

Untitled

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