Advertisement
keiaa070500

ticket booking system

Dec 7th, 2024 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ticket_Booking_System {
  4.     public static void main(String[] args) {
  5.         System.out.println();
  6.         Scanner input = new Scanner(System.in);
  7.         String seatType = "";
  8.        
  9.         while (true) {
  10.             System.out.println("Please choose between Regular and Premium seat...");
  11.             seatType = input.nextLine();
  12.             if (seatType.equals("Regular") || seatType.equals("Premium")) {
  13.                 break;
  14.             } else {
  15.                 System.out.println("\nERROR: INVALID SEAT TYPE. Please enter 'Regular' or 'Premium'.\n");
  16.             }
  17.         }
  18.        
  19.         System.out.println();
  20.         System.out.println("How many tickets would you like to purchase?");
  21.         int ticketCount = input.nextInt();
  22.         System.out.println();
  23.         input.close();
  24.        
  25.         double ticketPrice = 150.75;
  26.         double initialPrice = 0;
  27.         double discountedPrice = 0;
  28.         double totalPrice = 0;
  29.         boolean discount = ticketCount >= 5;
  30.         String appliedDiscount;
  31.        
  32.         initialPrice = ticketPrice * ticketCount;
  33.        
  34.         discountedPrice = (discount == true) ?
  35.                 (initialPrice - (initialPrice * 0.10)) :
  36.                 initialPrice;
  37.        
  38.         appliedDiscount = (discount == true) ?
  39.                 "10 percent" : "none";
  40.        
  41.         switch (seatType) {
  42.             case "Regular":
  43.                 totalPrice = discountedPrice;
  44.                 break;
  45.             case "Premium":
  46.                 totalPrice = discountedPrice * 1.5;
  47.                 break;
  48.         }
  49.        
  50.         System.out.println("Wilfrido Ma. Guerrero Theater");
  51.         System.out.println("UP-Diliman, Quezon City\n");
  52.        
  53.         System.out.println("Seat type\t: " + seatType);
  54.         System.out.println("No. of tickets\t: " + ticketCount + " tickets");
  55.         System.out.println("Initial price\t: " + "\u20b1 " + initialPrice);
  56.         System.out.println("Discount\t: " + appliedDiscount);
  57.         System.out.println("-----------------------------");
  58.         System.out.println("Total price\t: " + "\u20b1 " + totalPrice);
  59.         System.out.println();
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement