Advertisement
Guest User

Untitled

a guest
May 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. package assessment;
  2.  
  3. import java.util.*;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class UserInterface {
  7.  
  8. public void begin() {
  9.  
  10. // create the Insect ArrayList to store the data while the program is running
  11. ArrayList<Entertainment> insectus = new ArrayList<Entertainment>();
  12. // display the menu and process Butterfly & Beetle data
  13. boolean finished = false;
  14. while (!finished) {
  15. // a loop to allow the program to continue until the user chooses to exit
  16. // program
  17. int selection = showMenu();
  18. switch (selection) {
  19. case 1:
  20. Entertainment.add(addMovies());
  21. break;
  22.  
  23. case 2:
  24. //Entertainment.add(addGame());
  25. break;
  26.  
  27. case 3:
  28. JOptionPane.showMessageDialog(null, "Displaying the Entertainment information...", "Entertainment List",
  29. JOptionPane.PLAIN_MESSAGE);
  30. //for (int i = 0; i < Entertainment.size(); i++) {
  31. //JOptionPane.showMessageDialog(null, Entertainment.get(i), "Entertainment Details",
  32. //JOptionPane.PLAIN_MESSAGE);
  33. }
  34.  
  35. case 4:
  36. finished = true; // the boolean variable 'finished' is used to control the loop
  37. JOptionPane.showMessageDialog(null,
  38. "*** Program Ended ***\n" + "*** Thank you for using this program ***");
  39. break;
  40. default:
  41. JOptionPane.showMessageDialog(null, "\n*** Invalid Selection ***\n", "ERROR",
  42. JOptionPane.ERROR_MESSAGE);
  43. } // end switch
  44. } // end while loop
  45.  
  46. } // end begin()
  47.  
  48. // showMenu() – User’s program selection menu
  49. public int showMenu() {
  50. int selection = 0;
  51. String stringSelection = JOptionPane.showInputDialog(
  52. "******* MENU *******\n\n"
  53. + "1. Add a new Movie\n"
  54. + "2. Add a New Game\n"
  55. + "3. Display Entertainment Information\n"
  56. + "4. End\n"
  57. + "Type in the number of your selection and click OK:");
  58. selection = Integer.parseInt(stringSelection.trim());
  59. return selection; // end ShowMenu()
  60. }
  61.  
  62. // addMovie() – Method to collect Movie data
  63. public Movies addMovies() {
  64. String eType = JOptionPane.showInputDialog(null, "\nWhat type of Entertainment is it? ").trim();
  65. int profitMade = 0;
  66. do {
  67. String eProfitMade = JOptionPane.showInputDialog(null, "\nHow much profit did this make? ");
  68. double doubleProfitMade = Double.parseDouble(eProfitMade);
  69. profitMade = (int) doubleProfitMade;
  70. if (profitMade <= 0) {
  71. JOptionPane.showMessageDialog(null, "Error - Profit must be greater than zero", "ERROR",
  72. JOptionPane.ERROR_MESSAGE); // check that value is not negative and not zero
  73. }
  74. } while (profitMade <= 0);
  75.  
  76.  
  77.  
  78. String eYearReleased = JOptionPane.showInputDialog(null, "\nWhen was this released? ").trim();
  79. int lifespan = 0;
  80. do {
  81. String stringValidLifespan = JOptionPane.showInputDialog(null, "\nWhat is the expected life time of the Movie? ");
  82. double doubleLifespan = Double.parseDouble(stringValidLifespan);
  83. lifespan = (int) doubleLifespan;
  84. if(lifespan <= 0) {
  85. JOptionPane.showMessageDialog(null, "Error - life time must be greater than zero", "ERROR",
  86. JOptionPane.ERROR_MESSAGE);
  87. while (lifespan <= 0);
  88. String movieName = "";
  89. do {
  90. String stringValidMN = JOptionPane.showInputDialog(null, "\nWhat is the title of this movie? ");
  91. double doubleMN = Double.parseDouble(stringValidMN);
  92. movieName = (String) movieName;
  93. if(movieName == "") {
  94. JOptionPane.showMessageDialog(null, "Error - Movie Name cannot be Blank", "ERROR",
  95. JOptionPane.ERROR_MESSAGE);
  96. } while (movieName
  97.  
  98.  
  99. String directorName
  100. }
  101.  
  102. }
  103. }
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement