This is what I'm trying to do:
Create an application that contains an enumeration 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. Assume that the business is open from 11 to 5 on Sunday, 9 to 9 on weekdays, and 9 to 6 on Saturday.
This is what I have:
import javax.swing.JOptionPane;
public class DayOfWeek {
Day day;
public void Day(Day day) {
this.day = day;
}
public void businessHours() {
switch (day) {
case SATURDAY: System.out.println("Open from 9 to 6.");
break;
case SUNDAY: System.out.println("Open from 11 to 5.");
break;
default: System.out.println("Open from 9 to 9.");
break;
}
}
public static void main(String[] args) {
String dayInput = JOptionPane.showInputDialog("Please input a day: ");
EnumDay sixthDay = new EnumDay(Day.SATURDAY);
sixthDay.businessHours();
EnumDay seventhDay = new EnumDay(Day.SUNDAY);
seventhDay.businessHours();
if (dayInput == "Saturday")
{
JOptionPane.showMessageDialog(null, sixthDay.businessHours());
System.exit(0);
}
else if (dayInput == "Sunday")
{
JOptionPane.showMessageDialog(null, seventhDay.businessHours());
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null, default.businessHours());
System.exit(0);
}
}
}
and the enum class:
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
Please help how I can do the comparison and the print out. Thank you.