-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeartRate.java
More file actions
92 lines (65 loc) · 2.26 KB
/
Copy pathHeartRate.java
File metadata and controls
92 lines (65 loc) · 2.26 KB
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
// This program checks your heart rate according to your age
import static java.lang.System.out;
import static java.lang.System.in;
import java.util.Scanner;
class HeartRate
{
private final String name;
private final int age;
private final int VALUE = 220;
private final float LOWER_LIMIT = 50.0f;
private final float UPPER_LIMIT = 85.0f;
private static final Scanner INPUT = new Scanner (in);
HeartRate( String n, int a )
{
name = n;
age = a;
}
String targetedHeartRate()
{
float lowEnd = maxHeartRate() * ( LOWER_LIMIT / 100.0f );
float highEnd = maxHeartRate() * ( UPPER_LIMIT / 100.0f ) ;
String concatenate = (int)lowEnd + " - "+ (int)highEnd;
return concatenate;
}
int maxHeartRate()
{
int result = VALUE - age;
return result;
}
void print()
{
out.println(" Name : " + name);
out.println(" Age : " + age);
out.println(" Maximum heart rate : " + maxHeartRate() + " beats per minute");
out.println(" Targeted heart rate range : " + targetedHeartRate() + " beats per minute");
}
public static void main(String [] args)
{
String temp;
String name;
int age;
HeartRate [] obj;
obj = new HeartRate [5];
for( int i = 0; i < 5; i++ )
{
out.println();
out.print(" Enter name person " + (i+1) + " : ");
name = INPUT.nextLine();
out.print(" Enter age person " + (i+1) + " : ");
temp = INPUT.nextLine();
age = Integer.parseInt(temp);
if(age <= 0)
{
out.println();
out.println("Invalid input !! Input again . .");
i--;
continue;
}
obj[i] = new HeartRate(name,age);
out.println();
obj[i].print();
out.println();
}
}
}