Answer to Question #233033 in Java | JSP | JSF for Siya

Question #233033

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.


1
Expert's answer
2021-09-04T00:34:23-0400
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
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS