It’s coming up to pantomime season and CIT are planning on staging their first ever pantomime in the Rory Gallagher theatre. You have been asked to design and develop a Java application for box office staff to help them manage the bookings for the theatre.
The program should be generic so that it can, with minimal modification, work for any size theatre with a rectangular arrangement of seats.
Download full brief here
Download source code here
// Start of code--------------------- import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Scanner; /* Usage notes: * Redistribution, alteration and use of this code with or without * modification, are permitted provided that the following conditions * are met: * * In no event shall the copyright owner be liable for any direct, indirect, * incidental, special, exemplary, or consequential damages arising in any * way out of the use of this software, even if advised of the possibility * of such damage. */ public class TicketSystem { public static void main(String[] args) { NumberFormat numberFormat = new DecimalFormat("\u20AC#,##0.00"); Scanner input = new Scanner(System.in); final double costPremium = 10.00; final double costRegular = 7.50; final double costEconomy = 5.00; final int rowsPrem = 2; final int rowsReg = 6; final int rowsEcon = 2; final int seatColumns = 15; int premNumTotal = 0, regNumTotal = 0, econNumTotal = 0, premCancel = 0, regCancel = 0, econCancel = 0; int buySeats = 0, cancel = 0, yes, choice = 0; // Theatre banner printStars(); System.out.println("************** Pantomine ***************"); printStars(); System.out.println("****** The Rory Galagher Theatre *******"); printStars(); // Seat symbol legend System.out.println("\n\t\t A ‘#’ symbol represents an available seat "); System.out.println("\n\t\t A ‘P’ represents a booked premium seat. "); System.out.println("\n\t\t An ‘R’ represents a booked regular seat."); System.out.println("\n\t\t An ‘E’ represents a booked economy seat. "); // Stage layout System.out .println("\n\t | STAGE |"); System.out .println("\t |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|\n"); // Seat layout printSeats(); // Ticket purchase section do { System.out .println("\n\t\tWhat type of seat do you want to buy tickets for?"); seatPriceMenu(); // while(! input.hasNextInt()) choice = input.nextInt(); while (choice < 1 || choice > 3) { System.out .println("\n\t\tIncorrect input!!\n\tWhat type of seat do you want to buy tickets for?"); seatPriceMenu(); choice = input.nextInt(); } switch (choice) { case 1: System.out .println("\n\t\tYou would like to book some Premium Seats - " + numberFormat.format(costPremium) + " each."); System.out .print("\n\t\tHow many tickets do you want to buy : "); buySeats = input.nextInt(); if (buySeats > rowsPrem * seatColumns - premNumTotal) { System.out.print("You cannot book " + buySeats + " tickets as there are only " + (rowsPrem * seatColumns - premNumTotal) + " seats available."); } break; case 2: System.out .println("\t\tYou would like to book some Regular Seats - " + numberFormat.format(costRegular) + " each."); System.out .print("\n\t\tHow many tickets do you want to buy : "); buySeats = input.nextInt(); if (buySeats > rowsReg * seatColumns - regNumTotal) { System.out.print("You cannot book " + buySeats + " tickets as there are only " + (rowsReg * seatColumns - regNumTotal) + " seats available."); } break; case 3: System.out .println("\t\tYou would like to book some Economy Seats - " + numberFormat.format(costEconomy) + " each."); System.out .print("\n\t\tHow many tickets do you want to buy : "); buySeats = input.nextInt(); if (buySeats > rowsEcon * seatColumns - econNumTotal) { System.out.print("You cannot book " + buySeats + " tickets as there are only " + (rowsEcon * seatColumns - econNumTotal) + " seats available."); } break; default: break; } if (choice == 1) { if (buySeats <= (rowsPrem * seatColumns - premNumTotal)) { premNumTotal += buySeats; System.out.print("\n\t\tYou want to buy " + premNumTotal + " Seats, "); } System.out.print("total cost : " + numberFormat.format(costPremium * premNumTotal) + "\n"); } if (choice == 2) { if (buySeats <= (rowsReg * seatColumns - regNumTotal)) { regNumTotal += buySeats; System.out.print("\n\t\tYou want to buy " + regNumTotal + " Seats, "); } System.out .print("total cost : " + numberFormat .format(costRegular * regNumTotal) + "\n"); } if (choice == 3) { if (buySeats <= (rowsEcon * seatColumns - econNumTotal)) { econNumTotal += buySeats; System.out.print("\n\t\tYou want to buy " + econNumTotal + " Seats, "); } System.out.print("total cost : " + numberFormat.format(costEconomy * econNumTotal)); } System.out.print("\t\t"); underline(); System.out .print("\n\n\t\tWould you like to book more tickets ? Enter 1 for yes or 2 for no : "); yes = input.nextInt(); } while (yes == 1); // Ticket amount and cost total int numTotal = premNumTotal + regNumTotal + econNumTotal - premCancel - regCancel - econCancel; double costTotal = costPremium * premNumTotal + costRegular * regNumTotal + costEconomy * econNumTotal - costPremium * premCancel - costRegular * regCancel - costEconomy * econCancel; System.out .println("\n\n\t\tYou have selected not to book more tickets"); System.out.println("\n\t\tYou provisionally booked " + numTotal + " tickets"); System.out.println("\t\tYour Subtotal is : " + numberFormat.format(costTotal)); System.out.print("\t\t"); dottedUnderline(); // Ticket cancelling section System.out .print("\n\n\t\tWould you like to cancel tickets ? Enter 1 for yes or 2 for no : "); yes = input.nextInt(); while (yes < 1 || yes > 2) { System.out .println("\n\t\tIncorrect input!!\n\t\tWould you like to cancel tickets ? Enter 1 for yes or 2 for no : "); yes = input.nextInt(); } while (yes == 1) { System.out.println("\n\t\tWhat ticket would you like to cancel?"); seatPriceMenu(); choice = input.nextInt(); switch (choice) { case 1: System.out .println("\n\t\tYou would like to cancel some Premium Seats - " + numberFormat.format(costPremium) + " each."); System.out .print("\n\t\tHow many tickets do you want to cancel : "); cancel = input.nextInt(); if (cancel > premNumTotal) { System.out.print("You cannot cancel " + cancel + " tickets as you only have " + premNumTotal + " tickets purchased."); } break; case 2: System.out .println("\t\tYou would like to cancel some Regular Seats - " + numberFormat.format(costRegular) + " each."); System.out .print("\n\t\tHow many tickets do you want to cancel : "); cancel = input.nextInt(); if (cancel > regNumTotal) { System.out.print("You cannot cancel " + cancel + " tickets as you only have " + regNumTotal + " tickets purchased."); } break; case 3: System.out .println("\t\tYou would like to cancel some Economy Seats - " + numberFormat.format(costEconomy) + " each."); System.out .print("\n\t\tHow many tickets do you want to cancel : "); cancel = input.nextInt(); if (cancel > econNumTotal) { System.out.print("You cannot cancel " + cancel + " tickets as you only have " + econNumTotal + " tickets purchased."); } break; default: break; } if (choice == 1) { if (cancel <= premNumTotal) { premCancel += cancel; System.out.print("\n\t\tYou want to cancel " + premCancel + " Seats, "); } System.out.print("total cost canceled : " + numberFormat.format(costPremium * premCancel) + "\n"); // premNumTotal-=cancel; } if (choice == 2) { if (cancel <= regNumTotal) { regCancel += cancel; System.out.print("\n\t\tYou want to cancel " + regCancel + " Seats, "); } System.out.println("total cost canceled : " + numberFormat.format(costRegular * regCancel) + "\n"); } if (choice == 3) { if (cancel <= econNumTotal) { econCancel += cancel; System.out.print("\n\t\tYou want to cancel " + econCancel + " Seats, "); } System.out.println("total cost canceled : " + numberFormat.format(costEconomy * econCancel) + "\n"); } System.out.print("\t\t"); underline(); System.out .print("\n\n\t\tWould you like to cancel more tickets ? Enter 1 for yes or 2 for no : "); yes = input.nextInt(); } input.close(); // Ticket amount and cost total System.out .println("\n\t\tYou booked " + numTotal + " tickets in total"); System.out.println("\t\tYour total cost is : " + numberFormat.format(costTotal)); System.out.print("\n\t\t\t Selected seat layout\n\n"); printSeats(); System.out.print("\n\t\t"); dottedUnderline(); // Purchase reports menus System.out.println("\n\n\t\tSales Summary"); System.out.print("\t\t"); reportUnderline(); System.out.println("\n\t\tNumber of premium tickets sold: " + (premNumTotal - premCancel)); System.out.println("\t\tNumber of regular tickets sold: " + (regNumTotal - regCancel)); System.out.println("\t\tNumber of economy tickets sold: " + (econNumTotal - econCancel)); System.out.println("\t\tTotal value of Ticket Sales: " + numberFormat.format(costTotal)); System.out.println("\n\t\tSales Bar Chart"); System.out.print("\t\t"); reportUnderline(); System.out.print("\n\t\tNumber of premium tickets sold: "); for (int premBar = 1; premBar <= premNumTotal - premCancel; premBar++) { System.out.print("|"); } System.out.print("\n"); System.out.print("\t\tNumber of regular tickets sold: "); for (int regBar = 1; regBar <= regNumTotal - regCancel; regBar++) { System.out.print("|"); } System.out.print("\n"); System.out.print("\t\tNumber of economy tickets sold: "); for (int econBar = 1; econBar <= econNumTotal - econCancel; econBar++) { System.out.print("|"); } System.out.println("\n\n\t\tTicket Availability"); System.out.print("\t\t"); reportUnderline(); System.out.println("\n\t\tPremium tickets: " + (rowsPrem * seatColumns - (premNumTotal - premCancel))); System.out.println("\t\tRegular tickets: " + (rowsReg * seatColumns - (regNumTotal - regCancel))); System.out.println("\t\tEconomy tickets: " + (rowsEcon * seatColumns - (econNumTotal - econCancel))); } // method for seat menu and prices public static void seatPriceMenu() { NumberFormat numberFormat = new DecimalFormat("\u20AC#0.00"); final double costPremium = 10.00; final double costRegular = 7.50; final double costEconomy = 5.00; System.out.println("\n\t\t[1] Premium Seats " + numberFormat.format(costPremium)); System.out.println("\t\t[2] Regular Seats " + numberFormat.format(costRegular)); System.out.println("\t\t[3] Economy Seats " + numberFormat.format(costEconomy)); System.out.print("\n\t\tEnter a value between 1, 2, or 3 : "); } // Top of banner public static void printStars() { int stars, lines; System.out.print("\t\t "); for (lines = 1; lines <= 1; lines++) { for (stars = 1; stars <= 40; stars++) System.out.print("~"); System.out.println(); System.out.print("\t\t "); } } public static void underline() { System.out.print("\n\t\t"); for (int underLine = 0; underLine <= 68; underLine++) { System.out.print("_"); } } public static void dottedUnderline() { for (int dottedUnderLine = 0; dottedUnderLine <= 34; dottedUnderLine++) { System.out.print("_ "); } } public static void reportUnderline() { for (int dottedUnderLine = 0; dottedUnderLine <= 51; dottedUnderLine++) { System.out.print("="); } } // Method for seat layout public static void printSeats() { final int rowsPrem = 2; final int rowsReg = 6; final int rowsEcon = 2; final int seatColumns = 15; int premSeats; int regSeats; int econSeats; int premColumn; int regColumn; int econColumn; for (premSeats = 0; premSeats < rowsPrem; premSeats++) { System.out.print("\t\t\t"); for (premColumn = 0; premColumn < seatColumns; premColumn++) { System.out.print(" #"); } System.out.println(); } { for (regSeats = 0; regSeats < rowsReg; regSeats++) { System.out.print("\t\t\t"); for (regColumn = 0; regColumn < seatColumns; regColumn++) { System.out.print(" #"); } System.out.println(); } { for (econSeats = 0; econSeats < rowsEcon; econSeats++) { System.out.print("\t\t\t"); for (econColumn = 0; econColumn < seatColumns; econColumn++) { System.out.print(" #"); } System.out.println(); } System.out.print("\t\t\t"); } } } } // End of code--------------------- |
0 comments:
Post a Comment
Please feel free to leave comments or ask questions related to the tutorials.