Advertisement
Guest User

Untitled

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