Question
I need to make a GUI that uses JTextField, JLabel, and JButton. I need to write event handlers to process the user data. I also
I need to make a GUI that uses JTextField, JLabel, and JButton.
I need to write event handlers to process the user data.
I also must add the project that contains the HealthProfile class to this project (this is shown below).
This needs to be done in Java.
The HealthProfileGUI should have:
JTextField objects to enter: name, age, height in feet, height in inches, weight is pounds.
JButton objects to display the BMI, category, and max heart rate
JLabels to describe all textboxes.
Code event hanklers for each button:
Display - Make sure all user input is present and valid. Use the HealthProfile class to process data. Display the results on the GUI.
Clear - Clear all text boxes on the GUI.
public class HealthProfile
{
//attributes
private String name;
private short age;
private float weight;
private float height; // measured in total inches
//constructors
public HealthProfile()
{
name = "unknown";
age = 0;
weight = 0.0f;
height = 0.0f;
}
public HealthProfile(String name, short age, float weight, float height) {
this.name = name;
this.age = age;
this.weight = weight;
this.height = height;
}
// behaviors
public float getBMI()
{
return (float) ((weight * 703) / Math.pow(height, 2.0f));
}
public String getCategory()
{
float bmi = getBMI();
if( bmi < 18.5f )
return "Underweight";
else if( bmi >= 18.5 && bmi < 25)
return "Normal";
else if( bmi >= 25 && bmi < 30 )
return "Overweight";
else
return "Obese";
}
public float getMaxHR()
{
return 220 - age;
}
//getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public short getAge() {
return age;
}
public void setAge(short age)
{
if( age > 0 && age < 150)
this.age = age;
else
this.age = 0;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight)
{
if( weight > 0.0 && weight < 1000.0f )
this.weight = weight;
else
this.weight = 0.0f;
}
public float getHeight() {
return height;
}
public void setHeight(float height_feet, float height_inches)
{
this.height = (height_feet * 12) + height_inches;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started