Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
4.5 kB
1
Indexable
Never
import java.util.*;

public class NugasConcerts {

    private static ArrayList<Concert> concerts = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        concerts.add(new Concert("Eras Tour", "VIP", 30000.00));
        concerts.add(new Concert("Eras Tour", "Patron", 24500.00));
        concerts.add(new Concert("Eras Tour", "GenAd", 18000.00));
        concerts.add(new Concert("SVT: Be the Sun Tour", "VIP", 20500.00));
        concerts.add(new Concert("SVT: Be the Sun Tour", "Patron", 15000.00));
        concerts.add(new Concert("5SOS: Sounds Live Feels Live", "VIP", 15500.00));
        concerts.add(new Concert("5SOS: Sounds Live Feels Live", "GenAd", 7500.00));

        while (true) {
            System.out.println("\n--- Nugas Concerts ---");
            System.out.println("1. Purchase Ticket");
            System.out.println("2. Exit");
            System.out.print("Enter your choice: ");

            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            switch (choice) {
                case 1:
                    purchaseTicket();
                    break;
                case 2:
                    System.out.println("Exiting program.");
                    scanner.close();
                    System.exit(0);
                default:
                    System.out.println("Invalid choice. Please enter a number between 1 and 2.");
            }
        }
    }

    private static void purchaseTicket() {
        displayConcerts();
        System.out.print("Enter ticket ID: ");
        int ticketId = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        Concert selectedConcert = concerts.get(ticketId - 1);
        System.out.print("Enter ticket quantity (max of 5 only): ");
        int quantity = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        if (quantity > 5) {
            System.out.println("Maximum ticket quantity is 5.");
            return;
        }

        double subtotal = selectedConcert.getPrice() * quantity;
        double serviceFee = subtotal * 0.05;
        double grandTotal = subtotal + serviceFee;

        System.out.println("You are purchasing " + quantity + " " + selectedConcert.getTicketType() + " of " + selectedConcert.getConcertName());
        System.out.println("Ticket price: PHP " + selectedConcert.getPrice());
        System.out.println("Subtotal: PHP " + subtotal);
        System.out.println("Service fee (5%): PHP " + serviceFee);
        System.out.println("Grand total: PHP " + grandTotal);

        System.out.print("Enter payment amount: PHP ");
        double paymentAmount = scanner.nextDouble();
        scanner.nextLine(); // Consume newline

        if (paymentAmount < grandTotal) {
            System.out.println("Insufficient payment amount.");
            return;
        }

        double change = paymentAmount - grandTotal;

        System.out.println("\n--- Receipt ---");
        System.out.println(selectedConcert.getConcertName());
        System.out.println(quantity + " " + selectedConcert.getTicketType() + " - PHP " + selectedConcert.getPrice() + " each");
        System.out.println("Subtotal: PHP " + subtotal);
        System.out.println("Service fee (5%): PHP " + serviceFee);
        System.out.println("Grand total: PHP " + grandTotal);
        System.out.println("Payment amount: PHP " + paymentAmount);
        System.out.println("Change: PHP " + change);
        System.out.println("Thank you for purchasing!");

        concerts.remove(ticketId - 1);
    }

    private static void displayConcerts() {
        System.out.println("Available concerts:");
        for (int i = 0; i < concerts.size(); i++) {
            System.out.println((i + 1) + ". " + concerts.get(i));
        }
    }
}

class Concert {
    private String concertName;
    private String ticketType;
    private double price;

    public Concert(String concertName, String ticketType, double price) {
        this.concertName = concertName;
        this.ticketType = ticketType;
        this.price = price;
    }

    public String getConcertName() {
        return concertName;
    }

    public String getTicketType() {
        return ticketType;
    }

    public double getPrice() {
        return price;
    }

    @Override
    public String toString() {
        return concertName + " - " + ticketType + " - PHP " + price;
    }
}
Leave a Comment