Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Project Name: IC17_HackerChallenge Extend IC17_iSleepy to include a prompt to ask the user's age. Based on the user input (for sleep hours) and the

Java Project Name: IC17_HackerChallenge

Extend IC17_iSleepy to include a prompt to ask the user's age. Based on the user input (for sleep hours) and the user's age group, report the appropriate sleep health category.

image text in transcribed

Write a Java console program that will monitor how much sleep you obtained each night last week and store the data (number of hours) into an array. After all 7 days have been entered, be sure to display the total number of hours slept in the week, the average number of hours slept last week, how many nights were of "Recommended" sleep, how many "May be Appropriate" and how many were "Not Appropriate". Then, based on average number of hours slept per night, determine the person's overall sleep health category (e.g. "Recommended", "May be Appropriate" or "Not Recommended"). ***Note: for regular credit - make the sleep health category determination based on your age group*** The Hacker Challenge will include a prompt for age.

Here is an example transaction with a user (for the Young Adults age group):

image text in transcribed

THIS IS MY CODE SO FAR. I JUST NEED TO ADD THE USERS AGE INPUT AND IT WILL BE SET. RIGHT now I just have the young age group.

import java.text.DecimalFormat;

import java.util.Scanner;

public class iSleepy {

// Declare a constant for the size

public static final int SIZE = 7;

public static void main(String[] args) {

Scanner consoleScanner = new Scanner(System.in);

DecimalFormat twoDPs = new DecimalFormat("0.00");

// Declare the arrays for hours slept

double[] hoursSlept = new double [SIZE];

//Declare the days in a week(pre-known)

String[] days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

//Declare the sum and average

double sum = 0.0, average;

int rec = 0, app = 0, notRec= 0;

//Let's loop through the array (allow user to enter values)

for (int i = 0; i

{

System.out.print("Enter number of hours slept on "+days[i]+" : ");

hoursSlept[i] = consoleScanner.nextDouble();

// Add the hours to the sum

sum += hoursSlept[i];

//Determine whether recommended, appropriate or not recommended

if(hoursSlept[i]>=7 && hoursSlept[i]

{

rec++;

}

else if(hoursSlept[i] 11)

notRec++;

else app++;

}

consoleScanner.close();

average = sum/hoursSlept.length;

System.out.println(" Total number of hours slept last week : "+twoDPs.format(sum)

+" Average Number of hours slept per night : "+twoDPs.format(average));

System.out.println(" According to the NSF, last week, you slept: "

+ rec+(rec==1?" Night":" Nights") +" of \"recommended\" sleep. "

+app+(app==1?" Night":" Nights")+" of \"appropriate\"sleep. "

+notRec+(notRec==1?" Night":" Nights")+" of \"not recommended\" sleep. ");

if (average>=6 && average

System.out.println("Overall, your sleep health (on average) is \"Recommended\"");

else if (average >=10 && average

{

System.out.println("Overall, your sleep health (on average) is \"May be appropriate\"");

}

else

System.out.println("Overall, your sleep health (on average is \"Not recommended\"");

}

}

National Sleep Foundation's Sleep Duration Recommendations Recommended Age Newborns 0-3 months May be appropriate Not recommended 11 to 13 hours 18 to 19 hours 14 to 17 hours Less than 11 hours More than 19 hours Infants 12 to 15 hours 10 to 11 hours Less than 10 hours 4-11 months 16 to 18 hours More than 18 hours Toddlers 11 to 14 hours to 10 hours Less than 9 hours 1-2 years 15 to 16 hours More than 16 hours Preschoolers 10 to 13 hours 8 to 9 hours Less than 8 hours 3-5 years 14 hours More than 14 hours School-aged Children 9 to 11 hours 7 to 8 hours Less than 7 hours 6-13 years 12 hours More than 12 hours Teenagers 8 to 10 hours 7 hours Less than 7 hours 14-17 years 11 hours More than 11 hours Young Adults to 9 hours 6 hours Less than 6 hours 18-25 years 10 to 11 hours More than 11 hours Adults to 9 hours 6 hours Less than 6 hours 26-64 years 10 hours More than 10 hours Older Adults 7 to 8 hours 5 to 6 hours Less than 5 hours 2 65 years 9 hours More than 9 hours

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

Students also viewed these Databases questions

Question

What is a cryptogram?

Answered: 1 week ago