-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeartRatesApp.java
93 lines (72 loc) · 2.95 KB
/
HeartRatesApp.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
/*
* Most of the code is taken from my assignment 6 submission, particularly the get/set methods
* and the calculation methods.
*/
// Importing javaFX libraries necessary to launch the application
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class HeartRatesApp extends Application { //initialize the HeartRatesApp class that will be used in the controller
// declare the variables necessary
private int birthDay;
private int birthMonth;
private int birthYear;
public HeartRatesApp(int birthMonth, int birthDay, int birthYear){
// initialize the constructor for all the variables
this.birthDay = birthDay;
this.birthMonth = birthMonth;
this.birthYear = birthYear;
}
public HeartRatesApp(){}
// Setters that will take in the values when used in the other file and set the variables
public void setBirthDay(int birthDay){
this.birthDay = birthDay;
}
public void setBirthMonth(int birthMonth){
this.birthMonth = birthMonth;
}
public void setBirthYear(int birthYear){
this.birthYear = birthYear;
}
// getters that will allow for obtaining the variables once defined
public int getBirthDay(){
return birthDay;
}
public int getBirthMonth(){
return birthMonth;
}
public int getBirthYear(){
return birthYear;
}
// this is random separator text to make it look good lol
public int getAge(){ // getAge method that returns the age of the person
return 2024 - birthYear;
}
public int getMaxHeartRate(){ // obtains the maximum heart rate for someone's age
return 220 - getAge();
}
public String getTargetHeartRateRange(){ // method that utilizes age and multipliers to find out the
// optimal heart range for an age.
int maxHeartRate = getMaxHeartRate();
int lowTarget = (int) (maxHeartRate * 0.5);
int highTarget = (int)(maxHeartRate * 0.85);
return lowTarget + " - " + highTarget + "bpm"; // returns the low end and high end of the heart rate range
}
// Start of JavaFX code - creating a "start" class
@Override
public void start(Stage stage) throws Exception{ // beginning start class used by javafx to set up the launch
Parent root = FXMLLoader.load(getClass().getResource("HeartRatesApp.fxml")); // getting the fxml
Scene scene = new Scene(root); // attaching scene graph to scene
stage.setTitle("Heart Rates App"); // setting the title of the application
stage.setScene(scene); // attaching the scene to the stage
stage.show(); // displaying the scene
}
public static void main(String[] args){
launch(args); // main class that will launch the heartratesapp application
}
}
/* Citations:Java How To Program, Late Objects
Paul Deitel; Harvey Deitel Chapter 12,13
*/