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
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
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
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 : 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
Step by step
Solved in 3 steps with 1 images