Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application that enables you to randomly record heart rates at four di

ID: 3712971 • Letter: C

Question

Create an application that enables you to randomly record heart rates at four different times throughout the day for yourself and at least one more person. Record the rate at 0700 (7 a.m.), 1200 (noon), 1700 (5 p.m.), and 2100 (9 p.m.). Your resting heart rate, or pulse, is the number of times your heart beats a minute. According to the American Heart Association, when you're seated or lying down and relaxed, a normal heart rate is between 60 and 100 beats a minute. Record the value as heart beats per minute. Generally, a lower heart rate at rest implies more efficient heart function and better cardiovascular fitness. A heart rate of less than 60 beats per minute (BPM) in adults is called bradycardia. However, well-trained athletes might have a normal resting heart rate closer to 40 beats a minute or lower. For example, the world record for the slowest heartbeat in a healthy human is 26 BPM. Too fast of a heart rate, more than 100 beats per minute (BPM) in adults, is called tachycardia.

Recall one way to take your pulse rate:

Find a watch or an electronic device with a second hand and place it on your right wrist or on the table next to your left hand.

After finding your pulse, count the number of beats for 20 seconds.

Multiply by 3 to get your heart rate, or beats per minute (or just count for 60 seconds for a math-free option).

For maximum credit create a two-dimensional array to hold the inputted data. If the same person and time are entered more than one time, store the last smallest value entered into the array. For example, if my pulse was 67 at 7 a.m., I might store 67 in my array at cell 0, 0. When I entered 75 for my roommate for the 7 a.m. recording, I’d store the 75 at cell 1,0 assuming rows were used to record different individuals. If I next had a reading for myself at 7 a.m. and it was 66, the 66 should replace the 67 at cell 0,0. But if my roommate’s next 7 a.m.’s recording was 79, the 75 should remain unchanged at cell 1, 0.

Create a user interface (console or Windows) to collect the data. After all data has been entered, display the results (Name and recordings for each time period). Be sure to include appropriate labels. For maximum credit define another array to store and retrieve the times as well as the names of the participant.

So you might end up with output that resembles:

                                                7 AM             Noon              5 PM             9 PM

Barbara Doyle                        70                   68                   72                   67

Jim Long                                   58                   65                   70                   65

Before the application closes store in a text file the names and an overall average pulse rate for the individual along with an indication of whether they have a bradycardia, tachycardia or normal heart rate. For maximum credit, write a modularized multi- class solution which include exception handling techniques and demonstrates that you can apply the many concepts illustrated throughout the semester.

Post your source code, test run and text file for this solution.

Explanation / Answer

code:

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class Takereadings {

String participants[] = new String[2];

String [] time = new String[4];

int [][] records = new int [time.length][participants.length];

boolean bradycardia[]= new boolean[participants.length];

boolean tachycardia[] = new boolean [participants.length];

BufferedWriter bw = null;

public void collectRecord(){

Scanner scan = new Scanner(System.in);

System.out.println("Enter two participants names");

for(int i=0;i<participants.length;i++){

participants[i]=scan.next();

}

System.out.println("Enter any 4 convenient times when you want to calculate participants heart rate");

for(int i = 0;i<time.length; i++){

time[i]= scan.next();

}

for(int i =0;i<time.length; i++){

for(int j =0; j< participants.length; j++){

System.out.println("Enter heart record for " + participants[j] +" at time "+time[i]);

int temp = scan.nextInt();

if(records[i][j] == 0)

records[i][j] = temp;

else{

if(records[i][j] > temp){

records[i][j] = temp;

}

}

if(records[i][j] < 60){

System.out.println("is "+participants[j] +" athletes?");

if(scan.next().equals("no")){

bradycardia[j] = true;

}

else{

bradycardia[j] = false;

}

}

if(records[i][j] > 100 ){

System.out.println("is "+participants[j] +" resting or lying down?");

if(scan.next().equals("yes")){

tachycardia[j] = true;

}

else

tachycardia[j] = false;

}

}

}

}

public void diaplayRecord() throws IOException{

bw = new BufferedWriter(new FileWriter("HeartRateRecords.txt"));

System.out.print(" ");

bw.write(" ");

for(int i=0;i<time.length;i++){

System.out.print(time[i]+ " ");

bw.write(time[i]+ " ");

}

System.out.print(" "+ participants[0]+ " ");

bw.write(" "+ participants[0]+ " ");

for(int i=0;i<time.length;i++){

System.out.print(records[i][0]+" ");

bw.write(records[i][0]+" ");

}

System.out.print(" "+ participants[1]+ " ");

bw.write(" "+ participants[1]+ " ");

for(int i=0;i<time.length;i++){

System.out.print(records[i][1]+" ");

bw.write(records[i][1]+" ");

}

for(int i =0;i<bradycardia.length;i++){

if(bradycardia[i] == true){

System.out.println(" "+ participants[i] +" have bradycardia");

bw.write(" "+ participants[i] +" have bradycardia");

}

}

for(int i =0;i<tachycardia.length;i++){

if(tachycardia[i] == true){

System.out.println(" "+ participants[i] +" have tachycardia");

bw.write(" "+ participants[i] +" have tachycardia");

}

}

bw.close();

}

public static void main(String args[]){

Takereadings obj = new Takereadings();

obj.collectRecord();

try {

obj.diaplayRecord();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

Test run:

Enter two participants names

user1

user2

Enter any 4 convenient times when you want to calculate participants heart rate

7am

12pm

5pm

9pm

Enter heart record for user1 at time 7am

67

Enter heart record for user2 at time 7am

45

is user2 athletes?

no

Enter heart record for user1 at time 12pm

78

Enter heart record for user2 at time 12pm

89

Enter heart record for user1 at time 5pm

101

is user1 resting or lying down?

yes

Enter heart record for user2 at time 5pm

78

Enter heart record for user1 at time 9pm

89

Enter heart record for user2 at time 9pm

78

7am 12pm 5pm 9pm  

user1 67 78 101 89

user2 45 89 78 78

user2 have bradycardia

user1 have tachycardia

Text file:

7am 12pm 5pm 9pm

user1 67 78 101 89

user2 45 89 78 78

user2 have bradycardia

user1 have tachycardia

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