Final answer:
To create an application that contains an enumeration representing the days of the week and display business hours for a chosen day, you can define an enum with the days of the week as its elements and additional properties like business hours. Prompt the user for a day and retrieve the business hours using the getBusinessHours() method.
Step-by-step explanation:
To create an application that contains an enumeration representing the days of the week, you can define an enum with the days of the week as its elements. Each element can also have additional properties, such as the business hours. Here's an example:
public enum DayOfWeek {
SUNDAY("11:00 AM to 5:00 PM"),
MONDAY("9:00 AM to 9:00 PM"),
TUESDAY("9:00 AM to 9:00 PM"),
WEDNESDAY("9:00 AM to 9:00 PM"),
THURSDAY("9:00 AM to 9:00 PM"),
FRIDAY("9:00 AM to 9:00 PM"),
SATURDAY("10:00 AM to 6:00 PM");
private String businessHours;
private DayOfWeek(String businessHours) {
this.businessHours = businessHours;
}
public String getBusinessHours() {
return businessHours;
}
}
After defining the enum, you can display a list of the days using a loop. Then, prompt the user for a day and retrieve the business hours using the getBusinessHours() method. Here's an example:
for (DayOfWeek day : DayOfWeek.values()) {
System.out.println(day);
}
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a day: ");
String userInput = scanner.nextLine();
DayOfWeek chosenDay = DayOfWeek.valueOf(userInput.toUpperCase());
System.out.println("Business hours for " + chosenDay + ": " + chosenDay.getBusinessHours());
This application will display the list of days and prompt the user to enter a day. It will then display the business hours for the chosen day based on the enum values.