-
Notifications
You must be signed in to change notification settings - Fork 0
/
OnlinePersonalTrainingAssistant.java
137 lines (109 loc) · 4.49 KB
/
OnlinePersonalTrainingAssistant.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class OnlinePersonalTrainingAssistant {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
UserInterface ui = new UserInterface();
ui.authenticateUser();
});
}
}
class User {
private String name;
private int age;
private double weight;
private double height; // Height in centimeters
private double bmi;
public User(String name, int age, double weight, double height, double bmi) {
this.name = name;
this.age = age;
this.weight = weight;
this.height = height;
this.bmi = bmi;
}
public String getName() {
return name;
}
public String getAge() {
return Integer.toString(age);
}
public String getWeight() {
return Double.toString(weight);
}
public String getHeight() {
return Double.toString(height);
}
public String getBMI() {
return String.format("%.2f", bmi);
}
public String getWorkoutAndDiet() {
String workoutPlan = "Your personalized workout plan:\n" +
"Monday: Chest and Triceps\n" +
"Tuesday: Back and Biceps\n" +
"Wednesday: Rest day\n" +
"Thursday: Legs and Shoulders\n" +
"Friday: Cardio and Abs\n" +
"Saturday: Rest day\n" +
"Sunday: Rest day";
String dietChart = "Your personalized diet chart:\n" +
"Breakfast: Oatmeal with fruits and a glass of milk\n" +
"Mid-Morning Snack: Greek yogurt with honey\n" +
"Lunch: Grilled chicken breast with brown rice and vegetables\n" +
"Afternoon Snack: Mixed nuts and a banana\n" +
"Dinner: Baked salmon with quinoa and steamed broccoli\n" +
"Before Bed: A glass of warm milk";
return workoutPlan + "\n\n" + dietChart;
}
// Add a method to interpret the BMI value
public String getBMIInterpretation() {
double bmiValue = this.bmi;
String interpretation;
if (bmiValue < 18.5) {
interpretation = "You are underweight.";
} else if (bmiValue >= 18.5 && bmiValue < 24.9) {
interpretation = "You are in the healthy weight range.";
} else if (bmiValue >= 25 && bmiValue < 29.9) {
interpretation = "You are overweight.";
} else {
interpretation = "You are obese.";
}
return interpretation;
}
}
class UserInterface {
private User currentUser;
public void authenticateUser() {
// Get user input
String name = JOptionPane.showInputDialog(null, "Enter your name:");
int age = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your age:"));
double weight = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter your weight (in kg):"));
double heightCm = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter your height (in cm):")); // Height in cm
// Convert height to meters
double heightM = heightCm / 100.0;
// Calculate BMI
double bmi = weight / (heightM * heightM);
currentUser = new User(name, age, weight, heightCm, bmi); // Store height in cm
displayGUI();
}
private void displayGUI() {
JFrame frame = new JFrame("Online Personal Training Assistant");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
JTextArea outputTextArea = new JTextArea();
outputTextArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(outputTextArea);
frame.add(scrollPane);
String name = currentUser.getName();
String age = currentUser.getAge();
String weight = currentUser.getWeight();
String height = currentUser.getHeight();
String bmiMessage = "Hello " + name + ", your BMI is " + currentUser.getBMI();
// Get BMI interpretation
String bmiInterpretation = currentUser.getBMIInterpretation();
String workoutAndDiet = currentUser.getWorkoutAndDiet();
outputTextArea.append("Name: " + name + "\nAge: " + age + " years\nWeight: " + weight + " kg\nHeight: " + height + " cm\n");
outputTextArea.append(bmiMessage + "\n" + bmiInterpretation + "\n\n" + workoutAndDiet);
frame.setVisible(true);
}
}