Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HowHealthy
- {
- public static void main(String[] args)
- {
- String name;
- char gender;
- double pounds, inches;
- int age, actLevel;
- //creates new scanner class
- Scanner scan = new Scanner(System.in);
- Healthy person = new Healthy();
- //takes in String name with validation
- boolean valid = true;
- do {
- System.out.print("\nPerson's name: ");
- name = scan.nextLine();
- valid = person.setName(name);
- if (!valid)
- System.out.println("Invalid Name - must have at least one character");
- } while (!valid);
- do {
- //takes in gender with validation
- System.out.print(name + ", are you male or female (M/F)? ");
- gender = scan.next().charAt(0);
- valid = person.setGender(gender);
- if (!valid)
- System.out.println("Invalid Gender - Acceptable inputs are: M, m, F, f");
- } while (!valid);
- do {
- //takes in weight
- System.out.print(name + "'s weight (pounds): ");
- pounds = scan.nextDouble();
- valid = person.setWeight(pounds);
- if (!valid)
- System.out.println("Invalid weight - must be at least 100 pounds.");
- } while (!valid);
- do {
- //takes in height with validation
- System.out.print(name + "'s height (inches): ");
- inches = scan.nextDouble();
- valid = person.setHeight(inches);
- if (!valid)
- System.out.println("Invalid height - must be between 60 and 84 inches inclusively.");
- } while (!valid);
- do {
- //takes in age with validation
- System.out.print(name + "'s age (years): ");
- age = scan.nextInt();
- valid = person.setAge(age);
- if (!valid)
- System.out.println("Invalid age - must be at least 18 years old.");
- }
- while (!valid);
- do {
- //prints all activity levels
- System.out.println("Activity Level: Use these categories:");
- System.out.println("\t1 - Sedentary (little or no exercise, desk job)");
- System.out.println("\t2 - Lightly active (light exercise/sports 1-3 days/wk)");
- System.out.println("\t3 - Moderately active (moderate exercise/sports 3-5 days/wk)");
- System.out.println("\t4 - Very active (hard exercise/sports 6-7 days/wk)");
- System.out.println("\t5 - Extra active (hard daily exercise/sports & physical job or\n\t\t 2X day training i.e marathon, contest etc.)");
- //takes in activity level with validation
- System.out.print("How active are you? ");
- actLevel = scan.nextInt();
- valid = person.setActLevel(actLevel);
- if (!valid)
- System.out.println("Invalid activity level - must be between 1 and 5 inclusively");
- } while (!valid);
- //prints all inputed information
- System.out.println(person.getName() + "'s information");
- System.out.println("Weight: " + person.getWeight() + " pounds");
- System.out.println("Height: " + person.getHeight() + " inches");
- System.out.println("Age: " + person.getAge() + " years");
- //prints gender, bmr, bmi, and tdee
- System.out.println("These are for a " + gender + ".");
- System.out.println("");
- System.out.printf("BMR is %.2f\n", person.calcBmr());
- System.out.printf("BMI is %.2f\n", person.calcBmi());
- System.out.printf("TDEE is %.2f\n\n", person.calcTdee());
- System.out.println(person.calcStatus());
- }//main
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement