Question: Create an application that contains an enumeration (enum) that represents the days of the week. Display a list of the days, then prompt the user
Create an application that contains an enumeration (enum) that represents the days of the week. Display a list of the days, then prompt the user for a day. Display business hours for the chosen day. Create your own business hours stored in an array; however, every day of the week should have different hours. Although companies do not normally have different business hours every day of the week, programming your code with this difference will help in finding and fixing coding errors.
I have most of the code, I am just having a problem getting the program to display the day and corresponding hours from the array.
import java.util.Scanner;
public class Assignment2 { public enum Days{ Sunday(0), Monday(1), Tuesday(2), Wednesday(3), Thursday(4), Friday(5), Saturday(6); private int value; // constructor for enum to initilaize the value private Days(int value){ this.value=value; } } public static void main(String[]args){ // Initialize Array String[]hours = {"1pm-6pm", "9am-8pm", "9am-7pm", "10am-10pm", "8am-10pm", "9am-11pm"}; Scanner input = new Scanner(System.in); // print days of the week for(Days day :Days.values()){ System.out.print(day); } // prompt the user to enter the day System.out.println("Enter Day: "); String day = input.nextLine(); // get enum object for entered day Days d; d = Days.valueOf("Sunday"); d = Days.valueOf("Monday"); d = Days.valueOf("Tuesday"); d = Days.valueOf("Wednesday"); d = Days.valueOf("Thursday"); d = Days.valueOf("Friday"); d = Days.valueOf("Saturday"); for (int counter = 0; counter < hours.length; counter++) System.out.print("Business Hours on " +day+ ": " +hours[counter]);
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
