Java Program to Determine Daily Work Schedule Based on Day and Health Status

 LiFiUnit4.java - Main Method

Program will determine the hours you need to work based on certain criteria.

Program should get input for day of week as an integer: Monday = 1; Tuesday = 3; etc through Sunday = 7.

Java Program to Determine Daily Work Schedule Based on Day and Health Status


Program should get input for “Are You Sick” as a Boolean.

Logic required:

Use an if statement to determine the day of the week and if you are sick or not.

  • If the day is Monday through Friday and you are NOT sick then perform the following:Using a switch statement, output:
  • Monday and Wednesday output “Work Hours for today are 8-5”
  • Tuesday output “Work Hours for today are 7-4”
  • Friday output “Work Hours for today are 8-12”
  • All other days, output “Take the day off”. (this should only be called on Thursday)All other days (Saturday and Sunday) output “Stay in bed!”Above should be in a do while loop that should continue until I enter “y” at the prompt: “Would you like to run again? (y/n)Mimic the output in the sample below exactly.Sample
    Enter the day of the week (, , , etc.): 1 Are you sick? (True or False): false Work Hours for today are 8-5Would you like to run again? (y/n) y Enter the day of the week (, , , etc.): 4 Are you sick? (True or False): false Take the day offWould you like to run again? (y/n) y Enter the day of the week (, , , etc.): 2 Are you sick? (True or False): true Stay in bed!

Would you like to run again? (y/n) y

Enter the day of the week (, , , etc.): 6

public class DailyWorkSchedule

{

public static void main (String[] args)

{

Scanner stdIn = new Scanner(System.in);


{System.out.print("Enter the day of the week (1=Mon, 2=Tue, 3=Wed, etc.):");

int myInt= stdIn.nextInt();

switch (myInt)

{

case 1:

System.out.println("Work hours for today are 8-5");

break;


case 2:

System.out.println("Work hours for today are 7-4");

break;

case 3:

System.out.println("Work hours for today are 8-5");

break;

case 4:

System.out.println("Take day off");

break;

case 5:

System.out.println("Work hours for today are 8-12");

break;

case 6:

System.out.println("Stay in bed!");

break;

case 7:

System.out.println("Stay in bed!");

break;

default:

System.out.println("Invalid"); }


system.out.print(are you sick?)

boolean sickClaim = stdIn.nextBoolean()


if (sickClaim == true)

{

system.out.println(Stay in bed!)

}

else

switch (workDay)


System.out.print("Would you like to run again? (y/n)");

more = stdIn.next().charAt(0);



}


} // end main

} // end DailyWorkSchedule


The answer 

Description:

This Java program prompts the user to enter the day of the week (using numbers 1 to 7 for Monday through Sunday) and whether they are sick (Boolean input). Based on these inputs, it determines and displays the appropriate work schedule or advice using conditional logic and a switch statement. The program repeats until the user decides to exit.


Explanation:

  • The program uses a do-while loop to allow repeated execution until the user enters 'n' at the prompt.

  • For each loop, the user enters the day (integer) and whether they are sick (true/false).

  • If the user is sick or it is the weekend (Saturday or Sunday), the output is "Stay in bed!".

  • Otherwise, the program uses a switch statement to determine the message for Monday to Friday:

    • Monday (1) & Wednesday (3): "Work Hours for today are 8-5"

    • Tuesday (2): "Work Hours for today are 7-4"

    • Friday (5): "Work Hours for today are 8-12"

    • Thursday (4): "Take the day off"

  • The program repeats until the user inputs 'n' to the question: "Would you like to run again? (y/n)"


Java Code (LiFiUnit4.java):

java

import java.util.Scanner; public class LiFiUnit4 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); char more; do { System.out.print("Enter the day of the week (1=Mon, 2=Tue, 3=Wed, etc.): "); int day = stdIn.nextInt(); System.out.print("Are you sick? (true or false): "); boolean isSick = stdIn.nextBoolean(); // Determine output based on the day and sick status if (isSick) { System.out.println("Stay in bed!"); } else if (day >= 1 && day <= 5) { switch (day) { case 1: System.out.println("Work Hours for today are 8-5"); break; case 2: System.out.println("Work Hours for today are 7-4"); break; case 3: System.out.println("Work Hours for today are 8-5"); break; case 4: System.out.println("Take the day off"); break; case 5: System.out.println("Work Hours for today are 8-12"); break; } } else if (day == 6 || day == 7) { System.out.println("Stay in bed!"); } else { System.out.println("Invalid"); } System.out.print("Would you like to run again? (y/n) "); more = stdIn.next().charAt(0); } while (more == 'y' || more == 'Y'); } }

  • The program closely follows your requirements and sample interaction.

  • All prompts, input types, and outputs are formatted to match the lab instructions and output specs.


📩 Need a similar solution? Email me: adel455@hotmail.com



Previous Post Next Post

Comments

Nepali Graphics - Learn design, Animation, and Progrmming