Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Today {
- public static void main (String[] args) {
- // Create array of Movies
- Movie[] myMovies = new Movie[6];
- // Initialize Movies
- myMovies[0] = new Movie(0, "Forrest Gump", 4);
- myMovies[1] = new Movie(1, "The Sting", 3);
- myMovies[2] = new Movie(2, "Star Wars", 5);
- myMovies[3] = new Movie(3, "LOTR: The Return of the King", 12);
- myMovies[4] = new Movie(4, "Raiders of the Lost Ark", 3);
- myMovies[5] = new Movie(5, "The Matrix", 7);
- // Menu-driven program (Code from P05)
- int choice = 0;
- while (choice != 9) {
- // Println choices
- System.out.println();
- System.out.println("Menu:");
- System.out.println("\t1 - List all movies");
- System.out.println("\t2 - Rent a movie");
- System.out.println("\t3 - Update rent count");
- System.out.println("\t4 - Earnings");
- System.out.println("\t9 - Exit");
- // Read choice input
- System.out.println();
- choice = Console.readInt("Please enter your choice: ");
- System.out.println();
- if (choice == 1) {
- // 2. It will list all his movies with its current rent count
- System.out.println("ID\tRented\tTitle");
- for (int i = 0; i < myMovies.length; i++) myMovies[i].getInfo();
- } else if (choice == 2) {
- // 3. It will let Andy choose what movie to rent out.
- System.out.println("ID\tRented\tTitle");
- for (int i = 0; i < myMovies.length; i++) myMovies[i].getInfo();
- // 4. Everytime a movie is rented, the program will update the rent count by one.
- int rentChoice = Console.readInt("Which movie ID to rent out? ");
- myMovies[rentChoice].rent();
- } else if (choice == 3) {
- System.out.println("ID\tRented\tTitle");
- for (int i = 0; i < myMovies.length; i++) myMovies[i].getInfo();
- // A1. Update/amend the rent count of any movie.
- int rentChoice = Console.readInt("Which movie ID to amend rent count? ");
- int newRentCount = Console.readInt("How many times was it rented? ");
- myMovies[rentChoice].updateRent(newRentCount);
- } else if (choice == 4) {
- // A2. Total earnings; assuming he earns $3.15 per rental of movies with rent count more than 10, and $2.10 for others.
- System.out.println("Earned\tID\tRented\tTitle");
- for (int i = 0; i < myMovies.length; i++) {
- System.out.printf("$%.2f\t", myMovies[i].getEarnings());
- myMovies[i].getInfo();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment