Create an application that contains an enumeration enum that
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.
Solution
Answer:
//DayOfWeek.Java
import java.util.Scanner;
public class DayOfWeek {
enum Week
{
SUN, MON, TUE, WED, THR, FRI, SAT
};
public static void main(String[] args) {
int position;
Week week = null;
String userEntry = null;
Scanner inputReader = new Scanner(System.in);
for(Week wek : Week.values())
{
System.out.print(wek + \" \");
}
System.out.println(\" \");
System.out.println(\"\ Enter the first three\"
+ \" letters of week to find the timings : \");
userEntry = inputReader.next().toUpperCase();
week = Week.valueOf(userEntry);
position = week.ordinal() + 1;
switch(position)
{
case 1:
System.out.println(\"So its \" + week
+ \", Business is open from 11 to 5\");
break;
case 2:
System.out.println(\"So its \" + week
+ \", Business is open from 9 to 9\");
break;
case 3:
System.out.println(\"So its \" + week
+ \", Business is open from 9 to 9\");
break;
case 4:
System.out.println(\"So its \" + week
+ \", Business is open from 9 to 9\");
break;
case 5:
System.out.println(\"So its \" + week
+ \", Business is open from 9 to 9\");
break;
case 6:
System.out.println(\"So its \" + week
+ \", Business is open from 9 to 9\");
break;
case 7:
System.out.println(\"So its \" + week
+ \", Business is open from 9 to 9\");
break;
default:
System.out.println(\"Invalid Entry!\");
}
}
}
----------------------------------------------------------
Sample Output:
SUN MON TUE WED THR FRI SAT
Enter the first three letters of week to find the timings :
SUN
So its SUN, Business is open from 11 to 5

