Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write Java code with comments for the following condition: You have been tasked to write a program to interpret the output of a bed pressure

Write Java code with comments for the following condition:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

You have been tasked to write a program to interpret the output of a bed pressure sensor. This sensor logs the activity of a sleeper once a second for a period of 24 hours and then outputs the data to a file. The possible values in the data file are as follows: 0 - Deep sleep (uninterrupted pressure sensed on the pad) 1 - Restless sleep (interrupted pressure sensed on the pad) 2 - Interrupted sleep (no pressure sensed on the pad; individual is not on the bed) The first data point is captured at 12:00 midnight and the last data point is captured at 11:59 pm. You may use the following example to read the data file, sleep_data.csv. import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors import java.util.Scanner; // Import the Scanner class to read text files public class ReadFile { public static void main(String[] args) { try { File myObj = new File("sleep_data.csv"); Scanner myReader = new Scanner(myObj); while (my Reader.hasNextLine()) { String data = myReader.nextLine(); System.out.println(data); myReader.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(): The above code will read the file and simply display the output on the screen. You must place the sleep_data.csv in the top level of your project folder (where the bin and src folders are). Required Submission: Calculate the following statistics and display in a tabular format as shown below: Sleep report for 24 hour period Wake Time: 4.699722222222222 hours after midnight Sleep Time: 21.4 hours after midnight Duration Deep Sleep: 5.994166666666667 hours Duration of Restless Sleep 0.6680555555555555 hours Duration of Interrupted Sleep 0.6375 hours Sleep Quality: 7.298402777777778 The equation to calculate sleep quality is as follows: 10 * (Deep Sleep/(8*3600) - (Restless Sleep *0.1/3600 - {Interrupted Sleep}0.2*/3600 Show a bar graph of how many seconds of sleep was recorded. The number of asterisks in the bar graph represents 10% of the total number of seconds of sleep. Do not show any bars for periods where no sleep was detected. Modify the bar graph so it displays seconds of sleep (as asterisks), restlessness (as plus signs), and interrupts (as minus signs): +20 points Sleep data aggregated by 1 hour periods: **************************** (45.23 min) +++++++++ (13.43 min) 1- (1.35 min) (49.30 min) ********************************* | +++++++ (10.70 min) ************************************ (55.22 min) |--- (4.78 min) |************************************ (60.00 min) ******** (11.97 min) (35.90 min) ********************** | + (0.12 min) (50.40 min) ********************************** | ++++++ (9.60 min) (51.63 min) ********************************** ++++ (6.23 min) |-- (2.12 min) Modify the sleep statistics so that time is reported in hours and minutes (or just minutes as appropriate) and sleep quality is displayed to a single digit of precision:+5 points Sleep report for 24 hour period Wake Time: Sleep Time: Duration Deep Sleep: Duration of Restless Sleep: Duration of Interrupted sleep: 4:41 (military time) 21:24 (military time) 5 hours 59 minutes 40 minutes 38 minutes You have been tasked to write a program to interpret the output of a bed pressure sensor. This sensor logs the activity of a sleeper once a second for a period of 24 hours and then outputs the data to a file. The possible values in the data file are as follows: 0 - Deep sleep (uninterrupted pressure sensed on the pad) 1 - Restless sleep (interrupted pressure sensed on the pad) 2 - Interrupted sleep (no pressure sensed on the pad; individual is not on the bed) The first data point is captured at 12:00 midnight and the last data point is captured at 11:59 pm. You may use the following example to read the data file, sleep_data.csv. import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors import java.util.Scanner; // Import the Scanner class to read text files public class ReadFile { public static void main(String[] args) { try { File myObj = new File("sleep_data.csv"); Scanner myReader = new Scanner(myObj); while (my Reader.hasNextLine()) { String data = myReader.nextLine(); System.out.println(data); myReader.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(): The above code will read the file and simply display the output on the screen. You must place the sleep_data.csv in the top level of your project folder (where the bin and src folders are). Required Submission: Calculate the following statistics and display in a tabular format as shown below: Sleep report for 24 hour period Wake Time: 4.699722222222222 hours after midnight Sleep Time: 21.4 hours after midnight Duration Deep Sleep: 5.994166666666667 hours Duration of Restless Sleep 0.6680555555555555 hours Duration of Interrupted Sleep 0.6375 hours Sleep Quality: 7.298402777777778 The equation to calculate sleep quality is as follows: 10 * (Deep Sleep/(8*3600) - (Restless Sleep *0.1/3600 - {Interrupted Sleep}0.2*/3600 Show a bar graph of how many seconds of sleep was recorded. The number of asterisks in the bar graph represents 10% of the total number of seconds of sleep. Do not show any bars for periods where no sleep was detected. Modify the bar graph so it displays seconds of sleep (as asterisks), restlessness (as plus signs), and interrupts (as minus signs): +20 points Sleep data aggregated by 1 hour periods: **************************** (45.23 min) +++++++++ (13.43 min) 1- (1.35 min) (49.30 min) ********************************* | +++++++ (10.70 min) ************************************ (55.22 min) |--- (4.78 min) |************************************ (60.00 min) ******** (11.97 min) (35.90 min) ********************** | + (0.12 min) (50.40 min) ********************************** | ++++++ (9.60 min) (51.63 min) ********************************** ++++ (6.23 min) |-- (2.12 min) Modify the sleep statistics so that time is reported in hours and minutes (or just minutes as appropriate) and sleep quality is displayed to a single digit of precision:+5 points Sleep report for 24 hour period Wake Time: Sleep Time: Duration Deep Sleep: Duration of Restless Sleep: Duration of Interrupted sleep: 4:41 (military time) 21:24 (military time) 5 hours 59 minutes 40 minutes 38 minutes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Why is it said that ideas are a dime a dozen?

Answered: 1 week ago