Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
4.8 kB
1
Indexable
Never
import java.util.Scanner;
import java.util.ArrayList;

public class CustomerMenu {

    private static ArrayList<Movie> shoppingCart = new ArrayList<>();
    private static ArrayList<Double> receipt = new ArrayList<>();

    public static void displayMenu(Scanner keyboard, ArrayList<Movie> action, ArrayList<Movie> comedy,
                                   ArrayList<Movie> romance, ArrayList<Movie> horror, ArrayList<Movie> kids) {
        System.out.println("Thank You For Choosing BlueBox! Please Select a Number from the List: ");
        System.out.println("1. Action");
        System.out.println("2. Comedy");
        System.out.println("3. Romance");
        System.out.println("4. Horror");
        System.out.println("5. Kids");
        System.out.println("6. View Shopping Cart");
        System.out.println("7. Checkout and Print Receipt");

        int userInput = keyboard.nextInt();

        switch (userInput) {
            case 1:
                displayMovies(action, "Action");
                break;
            case 2:
                displayMovies(comedy, "Comedy");
                break;
            case 3:
                displayMovies(romance, "Romance");
                break;
            case 4:
                displayMovies(horror, "Horror");
                break;
            case 5:
                displayMovies(kids, "Kids");
                break;
            case 6:
                displayShoppingCart();
                break;
            case 7:
                checkoutAndPrintReceipt();
                break;
            default:
                System.out.println("Invalid choice. Please select a number from 1-7.");
        }
    }

    private static void displayMovies(ArrayList<Movie> movies, String genre) {
        System.out.println("You have selected " + genre + ". Here is our current selection of " + genre + " movies:");

        // Use enhanced for loop to iterate through movies in the selected genre
        for (Movie movie : movies) {
            movie.print();
        }
    }

    private static void addToCart(int genreChoice, Scanner keyboard, ArrayList<Movie> action, ArrayList<Movie> comedy,
                                  ArrayList<Movie> romance, ArrayList<Movie> horror, ArrayList<Movie> kids) {
        ArrayList<Movie> selectedGenreList;

        switch (genreChoice) {
            case 1:
                selectedGenreList = action;
                break;
            case 2:
                selectedGenreList = comedy;
                break;
            case 3:
                selectedGenreList = romance;
                break;
            case 4:
                selectedGenreList = horror;
                break;
            case 5:
                selectedGenreList = kids;
                break;
            default:
                System.out.println("Invalid choice. Please select a number from 1-5.");
                return;
        }

        System.out.println("Select the index of the movie you want to add to the cart:");
        for (int i = 0; i < selectedGenreList.size(); i++) {
            Movie movie = selectedGenreList.get(i);
            System.out.println(i + 1 + ". " + movie.getName() + " - $" + movie.getRating());
        }

        int movieIndex = keyboard.nextInt() - 1; // Adjusting for zero-based indexing

        if (movieIndex >= 0 && movieIndex < selectedGenreList.size()) {
            Movie selectedMovie = selectedGenreList.get(movieIndex);
            shoppingCart.add(selectedMovie);
            receipt.add((double) selectedMovie.getRating());
            System.out.println("Movie added to the shopping cart.");
        } else {
            System.out.println("Invalid movie index.");
        }
    }

    private static void displayShoppingCart() {
        System.out.println("Shopping Cart:");
        double totalCost = 0.0;
        for (int i = 0; i < shoppingCart.size(); i++) {
            Movie movie = shoppingCart.get(i);
            System.out.println(i + 1 + ". " + movie.getName() + " - $" + movie.getRating());
            totalCost += movie.getRating();
        }
        System.out.println("Total Cost: $" + totalCost);
    }

    private static void checkoutAndPrintReceipt() {
        System.out.println("Receipt:");
        double totalCost = 0.0;
        for (int i = 0; i < shoppingCart.size(); i++) {
            Movie movie = shoppingCart.get(i);
            System.out.println(i + 1 + ". " + movie.getName() + " - $" + movie.getRating());
            totalCost += movie.getRating();
        }
        System.out.println("Total Cost: $" + totalCost);
        System.out.println("Thank you for shopping with BlueBox!");
        // Clear the shopping cart and receipt after checkout
        shoppingCart.clear();
        receipt.clear();
    }
}
Leave a Comment