Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please read all the question carefully and also include // (comments) when you w

ID: 3730342 • Letter: P

Question

Please read all the question carefully and also include // (comments) when you write the code and please make sure you follow the instructions. Thak you

Objective

To build a complete working Java program that offer practice with basic Java graphical user interface components and the interaction of a GUI with an object of a class.

Overview & Instruction                        

Write a Java program that will calculate a variety of health-related values based on user input via a graphical user interface.

Create (or enhance the previously-used) a HealthLog class. This Java class will store basic parameters based on the calories burned for working out. Design the class to store basic information about a person as well as to calculate various health parameters:

Class HealthLog

Data

Age (years)

Height (inches)

Weight (pounds)

Sex (character 'm' or 'f')

Activity type (either walking or running)

Speed walking or running (miles per hour)

Time working out (minutes)

Methods

Constructor(s) and set/get methods

Validate data

Calculate base calorie needs
(to maintain weight)

Calculate body mass index

Determine body mass index classification

Calculate calories burned walking or running

Calculate minimum target heart rate

Calculate maximum target heart rate

Your class should include a method for basic error checking. Build this method to return true of all information "set" into the object is value and false otherwise. Include "common sense" tests for all member variables of the class (for both upper and lower bounds). Any additional flexibility in error checking is optional.

Calculations required for this solution are defined below:

Body Mass Index (BMI)

where h is the height (inches) and w is the weight (pounds)

Body Minimum Target Heart Rate

60% maximum heart rate which is 217 - (0.85 x Age)

Body Maximum Target Heart Rate

80% maximum heart rate which is 217 - (0.85 x Age)

Body Mass Index Classification

From the body mass index, classify the user using the following criteria:

If the BMI is . . .

then the user is . . .

Below 18.5

Underweight

18.5 to 24.99

Normal

25.0 to 29.99

Overweight

30.0 to Up

Obese

Minimum Energy Requirements

Energy needed to maintain weight at bed rest or no activity.

For males:

66.5 + (13.75 x weight in kg) + (5.003 x height in cm) - (6.775 x age)

For females:

655.1 + (9.563 x weight in kg) + (1.850 x height in cm) - (4.676 x age)

Calories Spent During Workout

If running:

(weight in pounds) x (0.75) x (distance in miles)

If walking:

(weight in pounds) x (0.53) x (distance in miles)

Your solution should include two files: one containing the HealthLog class including the data and method definitions and a second file to contain the "driver" application. Your driver application should include a basic graphical user interface with text fields (including appropriate labels), a text area, and a button. You are free to read ahead to include other interface components such as checkboxes or drop-down lists if you wish.

When the user clicks the button …

All of the information is collected from the input text fields

The data are then “set” into the HealthLog object

The input is validated by a message passed to object to determine if all values are in range.

The various calculations methods are invoked and the results are retrieved from the object.

A summary health report is formatted as a String object and “set” into the text area including:

Calories burned during workout

Maximum and minimum target heart rate range

Body mass index and classification

Minimum daily energy requirements (assuming no activity)

Be very careful of the units of measure for the various calculations. You will also need to research some basic unit conversions to accomplish this solution.

Show transcribed image text

Write a Java program that will calculate a variety of health-related values based on user input via a graphical user interface.

Create (or enhance the previously-used) a HealthLog class. This Java class will store basic parameters based on the calories burned for working out. Design the class to store basic information about a person as well as to calculate various health parameters:

Class HealthLog

Data

Age (years)

Height (inches)

Weight (pounds)

Sex (character 'm' or 'f')

Activity type (either walking or running)

Speed walking or running (miles per hour)

Time working out (minutes)

Methods

Constructor(s) and set/get methods

Validate data

Calculate base calorie needs
(to maintain weight)

Calculate body mass index

Determine body mass index classification

Calculate calories burned walking or running

Calculate minimum target heart rate

Calculate maximum target heart rate

Your class should include a method for basic error checking. Build this method to return true of all information "set" into the object is value and false otherwise. Include "common sense" tests for all member variables of the class (for both upper and lower bounds). Any additional flexibility in error checking is optional.

Calculations required for this solution are defined below:

Body Mass Index (BMI)

where h is the height (inches) and w is the weight (pounds)

Body Minimum Target Heart Rate

60% maximum heart rate which is 217 - (0.85 x Age)

Body Maximum Target Heart Rate

80% maximum heart rate which is 217 - (0.85 x Age)

Body Mass Index Classification

From the body mass index, classify the user using the following criteria:

If the BMI is . . .

then the user is . . .

Below 18.5

Underweight

18.5 to 24.99

Normal

25.0 to 29.99

Overweight

30.0 to Up

Obese

Minimum Energy Requirements

Energy needed to maintain weight at bed rest or no activity.

For males:

66.5 + (13.75 x weight in kg) + (5.003 x height in cm) - (6.775 x age)

For females:

655.1 + (9.563 x weight in kg) + (1.850 x height in cm) - (4.676 x age)

Calories Spent During Workout

If running:

(weight in pounds) x (0.75) x (distance in miles)

If walking:

(weight in pounds) x (0.53) x (distance in miles)

BMI = 703w 3

Explanation / Answer

/**
*
*/
package healthlog;

import java.text.DecimalFormat;

/**
* @author PC
*
*/
public class HealthLog {
   private String name = new String();
   private String gender = new String();
   private double heightInch;
   private double weightPounds;
   private String activityType;
   private double speed;
   private double timeWorkingOut;
   private int age;
   private int maxHeartRate;
   private DecimalFormat df = new DecimalFormat("#.##");
   private int[] targetHeartRate = new int[2];
   private double distanceMiles;
  

  
//constructor to intialise object fields
   public HealthLog(String name, String gender, double heightInch, double weightPounds, String activityType,
           double speed, double timeWorkingOut, int age) {
       super();
       this.name = name;
       this.gender = gender;
       this.heightInch = heightInch;
       this.weightPounds = weightPounds;
       this.activityType = activityType;
       this.speed = speed;
       this.timeWorkingOut = timeWorkingOut;
       this.age = age;
   }

// to validate input double type
   public boolean validateDouble(String number) {
       boolean valid = true;
       double d = 0.0;
       try {
           d = Double.parseDouble(number);
       } catch (Exception ex) {
           valid = false;
       }
       return valid;
   }

   //method to calculate BMI
   public String calculateBMI() {
       double bmi = 0.0;
       bmi = (weightPounds * 703) / (heightInch * heightInch);
       return df.format(bmi);
   }

   //method to determine BMI class
   public String determineBMIClass() {
       double bmi = Double.parseDouble(calculateBMI());

       // interpret BMI
       if (bmi < 18.5) {
           return "Underweight";
       }

       else if (bmi >= 18.5 && bmi < 24.99) {
           return "Normal";
       }

       else if (bmi >= 25.0 && bmi < 29.99) {
           return "OverWeight";
       }

       else if (bmi >= 30.0) {
           return "Obese";
       }
       return null;
   }

   // Calculate Maximum Heart Rate
   public int calculateMaximumHeartRate() {
       maxHeartRate = (int) (217 - (0.85 * age));
       return maxHeartRate;
   }

   // Calculate Target Heart Rate
   public int[] calculateTargetHeartRate() {
       maxHeartRate = calculateMaximumHeartRate();
       targetHeartRate[0] = (maxHeartRate * 50) / 100;
       targetHeartRate[1] = (maxHeartRate * 85) / 100;
       return targetHeartRate;
   }
  
   //calculate calories burned
   public double calculateCaloriesBurned(){
       double cal=0;
       double distance = getDistanceMiles();
       if(activityType.equals("running")){
           cal= (weightPounds * 0.75)*distance;
       }
       if(activityType.equals("walking")){
           cal= (weightPounds * 0.53)*getDistanceMiles();
       }
       return cal;
      
   }

   //calculate distance in miles

   public double getDistanceMiles() {
       this.distanceMiles = timeWorkingOut*speed;
       return distanceMiles;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getGender() {
       return gender;
   }

   public void setGender(String gender) {
       this.gender = gender;
   }

   public double getHeightInch() {
       return heightInch;
   }

   public void setHeightInch(double heightInch) {
       this.heightInch = heightInch;
   }

   public double getWeightPounds() {
       return weightPounds;
   }

   public void setWeightPounds(double weightPounds) {
       this.weightPounds = weightPounds;
   }

   public String getActivityType() {
       return activityType;
   }

   public void setActivityType(String activityType) {
       this.activityType = activityType;
   }

   public double getSpeed() {
       return speed;
   }

   public void setSpeed(double speed) {
       this.speed = speed;
   }

   public double getTimeWorkingOut() {
       return timeWorkingOut;
   }

   public void setTimeWorkingOut(double timeWorkingOut) {
       this.timeWorkingOut = timeWorkingOut;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       this.age = age;
   }

   public int[] getTargetHeartRate() {
       return targetHeartRate;
   }

   public void setTargetHeartRate(int[] targetHeartRate) {
       this.targetHeartRate = targetHeartRate;
   }
  
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote