Fitness Quotient Minimum Heart Rate Maximum Heart Rate Heart Rate Series 0.919 68 80 68, 69, 76, 78, 77, 77, 78, 80 0.887 67 84 67, 69, 78, 83, 83, 84, 79, 82, 79, 84, 83, 82, 83, 84, 79, 83, 80, 78, 84, 84 0.894 63 78 63, 71, 73, 78, 76

Enhanced Discovering Computers 2017 (Shelly Cashman Series) (MindTap Course List)
1st Edition
ISBN:9781305657458
Author:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Chapter7: Input And Output: Extending Capabilities Of Computers And Mobile Devices
Section: Chapter Questions
Problem 8TF
icon
Related questions
icon
Concept explainers
Question

The code must be in Java

The program will read several series of heart rates from a file, compute the minimum, maximum, and fitness quotient for each series, and output the input data and computed information into a document. 

The final output should look like in the image given

input.txt

3

8

68

69

76

78

77

77

78

80

20

67

69

78

83

83

84

79

82

79

84

83

82

83

84

79

83

80

78

84

84

5

63

71

73

78

76

Fitness Quotient Minimum Heart Rate Maximum Heart Rate
Heart Rate Series
0.919
68
80
68, 69, 76, 78, 77, 77, 78, 80
0.887
67
84
67, 69, 78, 83, 83, 84, 79, 82, 79, 84, 83, 82, 83, 84, 79, 83, 80, 78, 84, 84
0.894
63
78
63, 71, 73, 78, 76
Transcribed Image Text:Fitness Quotient Minimum Heart Rate Maximum Heart Rate Heart Rate Series 0.919 68 80 68, 69, 76, 78, 77, 77, 78, 80 0.887 67 84 67, 69, 78, 83, 83, 84, 79, 82, 79, 84, 83, 82, 83, 84, 79, 83, 80, 78, 84, 84 0.894 63 78 63, 71, 73, 78, 76
Expert Solution
Step 1

Solution is provided step by step in the java language-

 

Following is the code written in java for the given problem:

 

Step 1 : Save the following code in Lab6.java

package com.bartleby;

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Lab6 {
   // Input text file name
   private String inputFile;
   // Array to store heart beats
   private int[][] heartBeats;
   private int recordCount = 0;
   // Constructor
   public Lab6(String fName) {
       this.inputFile = fName;
   }  
   // Method to read the heart beat from input file
   public void readInput() {
       int beatCount = 0;
       try {
           Scanner fReader = new Scanner(new FileReader(inputFile));
           recordCount = fReader.nextInt();
           heartBeats = new int[recordCount][];
           for(int i = 0; i < recordCount; i++) {
               beatCount = fReader.nextInt();
               heartBeats[i] = new int[beatCount];
               for(int j = 0; j < beatCount; j++) {
                   heartBeats[i][j] = fReader.nextInt();
               }
           }
           fReader.close();
       } catch (Exception ex) {
           ex.printStackTrace();
       }
       System.out.print("Input : ");
       for(int i = 0; i < recordCount; i++) {
           System.out.println(Arrays.toString(heartBeats[i]));
       }
   }  
   // Method to write the heart beat analysis to html file
   public void writeHTMLOutput(String htmlFile) {
       BufferedWriter bw = null;
       PrintWriter pw = null;
       double quotient = 0;
       int min = 0;
       int max = 0;
       String series;
       try {
           bw = new BufferedWriter(new FileWriter(htmlFile));
           pw = new PrintWriter(bw);
           pw.println("<html><head><style>.body_style {\r\n" +
                   "   background : #F1F1F1;\r\n" +
                   "}\n.fitness_table { font-size : 16px;\r\n" +
                   "border : 1px solid #5dade2;\r\n" +
                   " border-collapse : collapse; } .fitness_table td {\r\n" +
                   "   font-size : 16px;\r\n" +
                   "   border : 2px solid #5dade2;\r\n" +
                   " }</style></head><body class='body_style' >" +
                   "<br><h2 align='center'>WELCOME TO FITNESS ANALYSIS</h2><br>" +
                   "<table class='fitness_table'>\n" +
                   "<tr><td><b>Fitness Quotient</td><td><b>Minimum Heart Rate</td>" +
                   "<td><b>Maximum Heart Rate</td><td><b>Heart Rates Series</td></tr></b>");
           for(int i = 0; i < recordCount; i++) {
               quotient = 0;
               min = -1;
               max = -1;
               series = "";
               for(int j = 0; j < heartBeats[i].length; j++) {
                   if(heartBeats[i][j] < min || -1 == min) {
                       min = heartBeats[i][j];
                   }
                   if(heartBeats[i][j] > max) {
                       max = heartBeats[i][j];
                   }
                   if(0 == j) {
                       series = heartBeats[i][j] + "";
                   } else {
                       series += ", " + heartBeats[i][j];
                   }
               }
               quotient = (Math.round(((2.0*min)/(min+max))*1000))/1000.0;
               pw.println("<tr><td>" + quotient + "</td><td>" + min + "</td>" +
                   "<td>" + max + "</td><td>" + series + "</td></tr>");
           }
           pw.println("</tr></table></body></html>");
           pw.close();
       } catch (Exception ex) {
           ex.printStackTrace();
       }
              
   }
   public static void main(String[] args) {
       if(args.length < 2) {
           System.out.println("Usage : FitnessQuotient <input_file> <output_file>");
           return;
       }
       Lab6 fitness = new Lab6(args[0]);
       // Read the heart beat from input file
       fitness.readInput();
       fitness.writeHTMLOutput(args[1]);
       System.out.println("Open " + args[1] + " in browser");
   }  
}

Step 2

Step 2 : Create a file F:\Training\sample-input.txt and paste the following line

3 8 68 69 76 78 77 77 78 80 20 67 69 78 83 83 84 79 82 79 84 83 82 83 84 79 83 80 78 84 84 5 63 71 73 78 76

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning