Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class HowHealthy
- {
- public static void main(String[] args)
- {
- String name;
- String printGender;
- //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");
- }//if
- }//do
- while (!valid);
- boolean valid1 = true;
- do
- {
- //takes in gender with validation
- System.out.print(name + ", are you male or female (M/F)? ");
- String gender = scan.nextLine();
- //takes in weight
- System.out.print(name + "'s weight (pounds): ");
- double pounds = scan.nextDouble();
- valid1 = person.setWeight(pounds);
- if (pounds < 100)
- {
- System.out.println("Invalid weight - must be at least 100 pounds.");
- }//if
- }//do
- while (!valid1);
- do
- {
- //takes in height with validation
- System.out.print(name + "'s height (inches): ");
- double inches = scan.nextDouble();
- if (inches >= 85 || inches <= 59)
- {
- System.out.println("Invalid height - must be between 60 and 84 inches inclusively.");
- System.exit(1);
- }//if
- }//do
- while (!valid);
- //takes in age with validation
- System.out.print(name + "'s age (years): ");
- int age = scan.nextInt();
- if (age < 18)
- {
- System.out.println("Invalid age - must be at least 18 years old.");
- }
- //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? ");
- int actLevel = scan.nextInt();
- if (actLevel < 1 || actLevel > 5)
- {
- System.out.println("Invalid activity level - must be between 1 and 5 inclusively");
- System.exit(1);
- }
- //creates new Healthy object named david
- Healthy david = new Healthy();
- //prints all inputed information
- System.out.println(david.getName() + "'s information");
- System.out.println("Weight: " + david.getWeight() + " pounds");
- System.out.println("Height: " + david.getHeight() + " inches");
- System.out.println("Age: " + david.getAge() + " years");
- char gender;
- //determines if input is for a male or female
- // if (gender.equalsIgnoreCase("M"))
- printGender = "Male";
- // else
- printGender = "Female";
- //prints gender, bmr, bmi, and tdee
- System.out.println("These are for a " + printGender + ".");
- System.out.println("");
- System.out.printf("BMR is %.2f\n", david.calcBmr());
- System.out.printf("BMI is %.2f\n", david.calcBmi());
- System.out.printf("TDEE is %.2f\n\n", david.calcTdee());
- System.out.println(david.calcStatus());
- }//main
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement