Design a program using Java NetBeans (Console application). With the following enum class: public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } Create a second class called enumDayMood with a void method call telDayMood (). This method contain a switch case as follows: switch (day) { case MONDAY: JOptionPane.showMessageDialog (frame, "Mondays are bad."); break; case FRIDAY: JOptionPane.showMessageDialog (frame, "Fridays are better."); break; case SATURDAY: case SUNDAY: JOptionPane.showMessageDialog (frame, "Weekends are best."); break; default: JOptionPane.showMessageDialog (frame, “Midweek days are so-so."); break; } Create a method that will ask the user to enter a day of a week and the program should tell the mood of the day. If the user enter a wrong value the program should exit with 0.
import javax.swing.*;
import java.util.Scanner;
public class EnumDayMood {
public static Day readData() {
Scanner in = new Scanner(System.in);
Day day = null;
try {
System.out.print("Enter a day of week(use capital letters): ");
day = Day.valueOf(in.nextLine());
} catch (Exception e) {
System.exit(0);
}
return day;
}
public static void tellDayMood(Day day) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
switch (day) {
case MONDAY:
JOptionPane.showMessageDialog(frame, "Mondays are bad.");
break;
case FRIDAY:
JOptionPane.showMessageDialog(frame, "Fridays are better.");
break;
case SUNDAY:
case SATURDAY:
JOptionPane.showMessageDialog(frame, "Weekends are best.");
break;
default:
JOptionPane.showMessageDialog(frame, "Midweek days are so - so.");
}
}
public static void main(String[] args) {
tellDayMood(readData());
}
}
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
Comments
Leave a comment