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: 3732766 • 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.

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 bmi;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class HealthLog extends JFrame implements ActionListener {

   private Person person;

   private JLabel ageLabel = new JLabel("Person age: ");// for prompt
   private JTextField ageField = new JTextField(3); // for age entry

   private JLabel heightLabel = new JLabel("Person height (cm): ");// for prompt
   private JTextField heightField = new JTextField(4); // for height entry

   private JLabel weightLabel = new JLabel("Person weight (kg): ");// for prompt
   private JTextField weightField = new JTextField(4); // for weight entry

   JCheckBox checkBox1 = new JCheckBox("Male", true);
   JCheckBox checkBox2 = new JCheckBox("Female");

   JCheckBox checkBoxActivity1 = new JCheckBox("Walking", true);
   JCheckBox checkBoxActivity2 = new JCheckBox("Running");

   private JLabel speedLabel = new JLabel("Speed: ");// for prompt
   private JTextField speedField = new JTextField(3); // for speed entry

   private JLabel timeLabel = new JLabel("Time:(Minutes) ");// for prompt
   private JTextField timeField = new JTextField(3); // for speed entry

   private JLabel distanceLabel = new JLabel("Distance:(Miles) ");// for prompt
   private JTextField distanceField = new JTextField(3); // for speed entry

   private JTextArea displayTextArea = new JTextArea("", 10, 50); // declare text area
   private JScrollPane scrollPane; // scroll pane for the text area

   // declare all of the buttons
   private JButton enterButton = new JButton("Enter"); // buttons

   public HealthLog() { // constructor create the Gui
       this.setLayout(new FlowLayout()); // set JFrame to FlowLayout

       add(heightLabel);
       add(heightField);

       add(weightLabel);
       add(weightField);

       add(ageLabel);
       add(ageField);

       add(checkBox1);
       add(checkBox2);

       add(checkBoxActivity1);
       add(checkBoxActivity2);

       add(speedLabel);
       add(speedField);

       add(timeLabel);
       add(timeField);

       add(distanceLabel);
       add(distanceField);

       displayTextArea.setEditable(false); // make text area read only
       scrollPane = new JScrollPane(displayTextArea); // add text area to the scroll pane
       scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); // just need vertical scrolling

       add(scrollPane);

       add(enterButton);

       enterButton.addActionListener(this); // add the action listener to the buttons

       // when the user pushes the system close (X top right corner)
       addWindowListener( // override window closing method
               new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                       System.exit(0);// Attempt to exit application
                   }
               });
   } // BodyMassIndexGUI

   public void actionPerformed(ActionEvent e) { // process the clicks on all of the buttons
       String command = e.getActionCommand();

       if (command.compareTo("Enter") == 0)
           if (setDetails()) {
               findHelathDetails();
               displaydata();
           }
   } // actionPerformed

   private void findHelathDetails() {

       displayHeading();

   } // enterPersonNameHeightAndWeight

   private boolean setDetails() {
       person = new Person();
       try {
           person.setAge(Double.parseDouble(ageField.getText()));
           person.setHeight(Double.parseDouble(heightField.getText()));
           person.setWeight(Double.parseDouble(weightField.getText()));
           person.setGender(checkBox1.isSelected() ? "M" : "F");
           person.setActivity(checkBoxActivity1.isSelected() ? "Running" : "Walking");
           person.setSpeed(Double.parseDouble(speedField.getText()));
           person.setDistance(Double.parseDouble(distanceField.getText()));
           person.setTime(Double.parseDouble(timeField.getText()));
           return true;
       } catch (Exception e) {
           return false;
       }

   }

   private void displayHeading() {
       displayTextArea.setText("BMI "+"Body Minimum Target Heart Rate "+
               "Body Maximum Target Heart Rate "+ "Body Mass Index Classification "+
               "Minimum Energy Requirements "+ "Calories Spent During Workout");
       appendLine();

   } // displayHeading

   private void displaydata() {
       displayTextArea.append(person.calculateBMI() + " " + person.calculateMinimumTargetHeartRate() + " "
               + person.calculateMaximumTargetHeartRate() + " " + person.getBMIClassification() + " "
               + person.getMinimumEnergyRequirement() + " " + person.getCaloriesSpent());
       appendLine();

   } // displayHeading

   private void appendLine() {
       displayTextArea.append(
               "------------------------------------------------------------------------------------------------- ");
   } // appendLine

   // Main method create instance of class
   public static void main(String[] args) {
       HealthLog f = new HealthLog(); // Create instance of class
       f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // allow the code to close the program
       f.setBounds(200, 100, 900, 425); // Define position and size of app
       f.setTitle("BMI application"); // Set the title of the app
       f.setVisible(true); // Make the application visible
   } // main

}

package bmi;

public class Person {

   private double age;
   private double height;
   private double weight;
   private String gender;
   private String activity;
   private double speed;
   private double distance;
   private double time;

   public double getWeight() {
       return weight;
   }

   public void setWeight(double weight) {
       this.weight = weight;
   }

   public double getAge() {
       return age;
   }

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

   public double getHeight() {
       return height;
   }

   public void setHeight(double height) {
       this.height = height;
   }

   public String getGender() {
       return gender;
   }

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

   public String getActivity() {
       return activity;
   }

   public void setActivity(String activity) {
       this.activity = activity;
   }

   public double getSpeed() {
       return speed;
   }

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

   public double getTime() {
       return time;
   }

   public void setTime(double time) {
       this.time = time;
   }

   public double getDistance() {
       return distance;
   }

   public void setDistance(double distance) {
       this.distance = distance;
   }

   public double calculateBMI() {
       return (703 * getWeight()) / (Math.pow(getHeight(), 2));
   }

   public double calculateMinimumTargetHeartRate() {
       return (217 - (0.85 * getAge())) * 0.60;
   }

   public double calculateMaximumTargetHeartRate() {
       return (217 - (0.85 * getAge())) * 0.80;
   }

   public String getBMIClassification() {
       double bmi = calculateBMI();
       if (bmi < 18.5) {
           return "Underweight";

       } else if (bmi > 18.5 && bmi <= 24.99) {
           return "Normal";
       } else if (bmi > 25 && bmi <= 29.99) {
           return "Overweight";
       } else if (bmi > 30) {
           return "Obese";
       }
       return "";
   }

   public double getMinimumEnergyRequirement() {
       if (getGender().equalsIgnoreCase("Male")) {
           return 66.5 + (13.75 * getWeight()) + (5.003 * getHeight()) - (6.775 * getAge());
       }
       if (getGender().equalsIgnoreCase("Female")) {
           return 655.1 + (9.563 * getWeight()) + (1.85 * getHeight()) - (4.676 * getAge());
       }
       return 0;
   }

   public double getCaloriesSpent() {
       if (getActivity().equalsIgnoreCase("Walking"))

       {
           return getWeight() * 0.75 * getDistance();
       }
       if (getActivity().equalsIgnoreCase("Running"))

       {
           return getWeight() * 0.53 * getDistance();
       }
       return 0;
   }

}

output:

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