Answered step by step
Verified Expert Solution
Question
1 Approved Answer
us Use Java You have been tasked to write a program to interpret the output of a bed pressure sensor. This sensor logs the activity
us
Use Java
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 (myReader.hasNextLine()) { String data = myReader.nextLine(); System.out.println(data); } 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). Wake Time can be calculated by determining when Interrupted sleep has occurred for at least 30 minutes (getting up and going to the bathroom wouldn't count if it took less than 30 minute) Sleep Time is the first time "Restless sleep or Deep sleep is encountered after the person has be determined to be out of bed (awake). Calculate the following statistics and display in a tabular format as shown below: Sleep report for 24 hour period Wake Time: Sleep Time: Duration Deep Sleep: Duration of Restless Sleep Duration of Interrupted sleep 4.699722222222222 hours after midnight 21.4 hours after midnight 5.994166666666667 hours 0.6680555555555555 hours 0.13722222222222222 hours Sleep Quality: 7.4 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 total number of asterisks in a bar graph represents 1% of the total number of seconds of sleep for that hour. Do not show any bars for periods where no sleep was detected. Sleep data aggregated by 1 hour periods: 0: **************************** ****************************** ********************************** 1: 2: 3: 4: 21: 22: 23: ************************************ ******** ********************** ******************************* ******************************* Extra Credit: 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: 0: **************************** (45.23 min) | +++++++++ (13.43 min) 1- (1.35 min) 1: ****************************** (49.30 min) |+++++++ (10.70 min) ********************************** (55.22 min) 2: (4.78 min) | ************************************ (60.00 min) 3: | ******** (11.97 min) 4: | ********************** (35.90 min) | + (0.12 min) 21: ******************************* (50.40 min) |++++++ (9.60 min) 22: ******************************* (51.63 min) 23: | ++++ (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 8 minutesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started