Guest User

Untitled

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. public class Today {
  2. public static void main (String[] args) {
  3.  
  4. // Create array of Movies
  5. Movie[] myMovies = new Movie[6];
  6.  
  7. // Initialize Movies
  8. myMovies[0] = new Movie(0, "Forrest Gump", 4);
  9. myMovies[1] = new Movie(1, "The Sting", 3);
  10. myMovies[2] = new Movie(2, "Star Wars", 5);
  11. myMovies[3] = new Movie(3, "LOTR: The Return of the King", 12);
  12. myMovies[4] = new Movie(4, "Raiders of the Lost Ark", 3);
  13. myMovies[5] = new Movie(5, "The Matrix", 7);
  14.  
  15. // Menu-driven program (Code from P05)
  16. int choice = 0;
  17. while (choice != 9) {
  18.  
  19. // Println choices
  20. System.out.println();
  21. System.out.println("Menu:");
  22. System.out.println("\t1 - List all movies");
  23. System.out.println("\t2 - Rent a movie");
  24. System.out.println("\t3 - Update rent count");
  25. System.out.println("\t4 - Earnings");
  26. System.out.println("\t9 - Exit");
  27.  
  28. // Read choice input
  29. System.out.println();
  30. choice = Console.readInt("Please enter your choice: ");
  31. System.out.println();
  32.  
  33. if (choice == 1) {
  34.  
  35. // 2. It will list all his movies with its current rent count
  36. System.out.println("ID\tRented\tTitle");
  37. for (int i = 0; i < myMovies.length; i++) myMovies[i].getInfo();
  38.  
  39. } else if (choice == 2) {
  40.  
  41. // 3. It will let Andy choose what movie to rent out.
  42. System.out.println("ID\tRented\tTitle");
  43. for (int i = 0; i < myMovies.length; i++) myMovies[i].getInfo();
  44.  
  45. // 4. Everytime a movie is rented, the program will update the rent count by one.
  46. int rentChoice = Console.readInt("Which movie ID to rent out? ");
  47. myMovies[rentChoice].rent();
  48.  
  49. } else if (choice == 3) {
  50.  
  51. System.out.println("ID\tRented\tTitle");
  52. for (int i = 0; i < myMovies.length; i++) myMovies[i].getInfo();
  53.  
  54. // A1. Update/amend the rent count of any movie.
  55. int rentChoice = Console.readInt("Which movie ID to amend rent count? ");
  56. int newRentCount = Console.readInt("How many times was it rented? ");
  57. myMovies[rentChoice].updateRent(newRentCount);
  58.  
  59. } else if (choice == 4) {
  60.  
  61. // A2. Total earnings; assuming he earns $3.15 per rental of movies with rent count more than 10, and $2.10 for others.
  62. System.out.println("Earned\tID\tRented\tTitle");
  63. for (int i = 0; i < myMovies.length; i++) {
  64. System.out.printf("$%.2f\t", myMovies[i].getEarnings());
  65. myMovies[i].getInfo();
  66. }
  67.  
  68. }
  69. }
  70. }
  71. }
Add Comment
Please, Sign In to add comment