Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package assessment;
- import java.util.*;
- import javax.swing.JOptionPane;
- public class UserInterface {
- public void begin() {
- // create the Insect ArrayList to store the data while the program is running
- ArrayList<Entertainment> insectus = new ArrayList<Entertainment>();
- // display the menu and process Butterfly & Beetle data
- boolean finished = false;
- while (!finished) {
- // a loop to allow the program to continue until the user chooses to exit
- // program
- int selection = showMenu();
- switch (selection) {
- case 1:
- Entertainment.add(addMovies());
- break;
- case 2:
- //Entertainment.add(addGame());
- break;
- case 3:
- JOptionPane.showMessageDialog(null, "Displaying the Entertainment information...", "Entertainment List",
- JOptionPane.PLAIN_MESSAGE);
- //for (int i = 0; i < Entertainment.size(); i++) {
- //JOptionPane.showMessageDialog(null, Entertainment.get(i), "Entertainment Details",
- //JOptionPane.PLAIN_MESSAGE);
- }
- case 4:
- finished = true; // the boolean variable 'finished' is used to control the loop
- JOptionPane.showMessageDialog(null,
- "*** Program Ended ***\n" + "*** Thank you for using this program ***");
- break;
- default:
- JOptionPane.showMessageDialog(null, "\n*** Invalid Selection ***\n", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- } // end switch
- } // end while loop
- } // end begin()
- // showMenu() – User’s program selection menu
- public int showMenu() {
- int selection = 0;
- String stringSelection = JOptionPane.showInputDialog(
- "******* MENU *******\n\n"
- + "1. Add a new Movie\n"
- + "2. Add a New Game\n"
- + "3. Display Entertainment Information\n"
- + "4. End\n"
- + "Type in the number of your selection and click OK:");
- selection = Integer.parseInt(stringSelection.trim());
- return selection; // end ShowMenu()
- }
- // addMovie() – Method to collect Movie data
- public Movies addMovies() {
- String eType = JOptionPane.showInputDialog(null, "\nWhat type of Entertainment is it? ").trim();
- int profitMade = 0;
- do {
- String eProfitMade = JOptionPane.showInputDialog(null, "\nHow much profit did this make? ");
- double doubleProfitMade = Double.parseDouble(eProfitMade);
- profitMade = (int) doubleProfitMade;
- if (profitMade <= 0) {
- JOptionPane.showMessageDialog(null, "Error - Profit must be greater than zero", "ERROR",
- JOptionPane.ERROR_MESSAGE); // check that value is not negative and not zero
- }
- } while (profitMade <= 0);
- String eYearReleased = JOptionPane.showInputDialog(null, "\nWhen was this released? ").trim();
- int lifespan = 0;
- do {
- String stringValidLifespan = JOptionPane.showInputDialog(null, "\nWhat is the expected life time of the Movie? ");
- double doubleLifespan = Double.parseDouble(stringValidLifespan);
- lifespan = (int) doubleLifespan;
- if(lifespan <= 0) {
- JOptionPane.showMessageDialog(null, "Error - life time must be greater than zero", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- while (lifespan <= 0);
- String movieName = "";
- do {
- String stringValidMN = JOptionPane.showInputDialog(null, "\nWhat is the title of this movie? ");
- double doubleMN = Double.parseDouble(stringValidMN);
- movieName = (String) movieName;
- if(movieName == "") {
- JOptionPane.showMessageDialog(null, "Error - Movie Name cannot be Blank", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- } while (movieName
- String directorName
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement