Created
November 15, 2014 19:26
-
-
Save yassaa/ae17159bb12d54c16f7a to your computer and use it in GitHub Desktop.
MovieBookingSystem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package exam.project.sketch; | |
import java.io.*; | |
import java.util.*; | |
public class Test_BookingSystem { | |
public static void main(String[] args) throws IOException{ | |
//BEGIN MOVIE-SELECTION - Yasamin | |
//creating Array list with 3 movies | |
Movie[] availableMovies = { | |
new Movie ( | |
"Die Hard 12 - THE SMACKDOWNENING", | |
new String[] {" 12.30 - 14.00", " 14.30 - 16.00", " 18.30 - 20.00"}, | |
"1"), | |
new Movie ( | |
"Fast and Furious 10", | |
new String[] {" 12.30 - 14.00", " 14.30 - 16.00", " 18.30 - 20.00"}, | |
"2"), | |
new Movie ( | |
"Zombievers 2", | |
new String[] {" 16.30 - 18.00", " 20.30 - 22.00"}, | |
"2") | |
}; | |
//create scanner | |
Scanner input = new Scanner(System.in); | |
//Calling methods to prompt user to select movie and time | |
Movie selectedMovie = promtUserMovieSelection(availableMovies, input); | |
System.out.println("\nYou have selected: " + selectedMovie.getMovieName() ); | |
String selectedTime = promtUserTimeSelection(selectedMovie.getTime(), input); | |
System.out.println("\n You have selected the movie: " + selectedMovie.getMovieName() + | |
"\n in the timeslot: " + selectedTime + " \n in cinema: " + selectedMovie.getCinema()); | |
//BEGIN SEAT-SELECTION - Ann | |
//create seating database object w 100 seats | |
SeatingDatabase cinema1 = new SeatingDatabase(100); | |
//create seating database object w 100 seats | |
SeatingDatabase cinema2 = new SeatingDatabase(60); | |
//choosing the right cinema | |
SeatingDatabase selectedCinema; | |
if (selectedMovie.getCinema() == "1"){ | |
selectedCinema = cinema1; | |
} | |
else selectedCinema = cinema2; | |
//print # of reserved and available seats | |
System.out.println("\nThe number of reserved seats is currently " + selectedCinema.NumberOfReservedSeats()); | |
System.out.println("The number of available seats is currently " + selectedCinema.NumberOfAvailableSeats() + "\n"); | |
//printing the seating chart for the selected cinema | |
selectedCinema.printSeatingChart(); | |
//asking user to reserve seats | |
Scanner userInput = new Scanner(System.in); | |
System.out.println("\nPlease enter the number of a seat you would like to reserve. You end the reservation by typing 0."); | |
int seatNumber = -10; | |
int sumOfReservedSeats = 0; | |
ArrayList<Integer> listOfReservations = new ArrayList<Integer>(); | |
//create do-while loop to reserve seats | |
do { | |
try{ | |
seatNumber = userInput.nextInt()-1; | |
//reserve and print statement if it's a valid seat | |
if (seatNumber > -1 && seatNumber < selectedCinema.getNumberOfSeats() && (selectedCinema.getSeatValue(seatNumber) == false)){ | |
selectedCinema.reserveSeat(seatNumber); | |
System.out.println("Seat number " + (seatNumber + 1) + " has been reserved."); | |
sumOfReservedSeats++; | |
//create an array list to hold index numbers of seats reserved | |
listOfReservations.add(seatNumber); | |
} | |
//print statement if user enters an invalid or reserved number | |
else if (seatNumber != -1){ | |
System.out.println("Please enter a valid, available seat number"); | |
} | |
} | |
catch(InputMismatchException e){ | |
System.err.println("Please try again. It has to be a whole Integer"); | |
userInput.next(); | |
} | |
} | |
while (seatNumber != -1); | |
//exit if no seats are reserved | |
if (sumOfReservedSeats == 0){ | |
System.out.println("You have not reserved any seats."); | |
System.exit(0); | |
} | |
//BEGIN ORDER - Oliver | |
//initialising new order | |
Order order1 = new Order(sumOfReservedSeats, 80); | |
System.out.println("\nYou have reserved " + order1.getNumberOfTickets() + " ticket(s) to the showing of " + selectedMovie.getMovieName()); | |
System.out.println("The total price of your selected tickets is " + order1.getTotalPrice() + " Danish kroner"); | |
//Let user choose how to proceed | |
String answer; | |
do{ | |
answer = userInput.nextLine().toLowerCase(); | |
if (answer.equals("yes")){ | |
System.out.println("You will now be taken to Payment Authorization\n"); | |
break; | |
} | |
else if (answer.equals("no")){ | |
System.out.println("We hope you come back another time"); | |
//Release reservations | |
for (int i = 0; i < listOfReservations.size(); ++i){ | |
selectedCinema.releaseSeat(listOfReservations.get(i)); | |
} | |
System.exit(0); | |
} | |
else if (answer != "no" || answer != "yes"){ | |
System.out.println("Do you wish to proceed? Please type 'Yes' or 'No'."); | |
} | |
} | |
while (answer != "no" || answer != "yes"); | |
// BEGIN USER registration - XX | |
//if system exit: Release reservations | |
//BEGIN PAYMENT - Oliver & Ann | |
//asking user to choose payment method. | |
System.out.println("Please select the preferred payment type.\nMastercard - choose 0\nVisa - choose 1\nPayPal - choose 2"); | |
int type = -1; | |
int i = -10; | |
//try loop to get a correct user input. Ensuring scanner input is an integer | |
do { | |
try{ | |
i = userInput.nextInt(); | |
if (i == 0){ | |
System.out.println("You have selected Mastercard payment"); | |
type = 0; | |
} | |
else if (i == 1){ | |
System.out.println("You have selected Visa payment"); | |
type = 1; | |
} | |
else if (i == 2){ | |
System.out.println("You have selected PayPal payment"); | |
type = 2; | |
} | |
else { | |
System.out.println("Please try again. You must enter a valid number."); | |
} | |
} | |
catch(InputMismatchException e){ | |
System.err.println("Please try again. It has to be a whole Integer"); | |
userInput.next(); | |
} | |
} while (i != 0 && i != 1 && i != 2); | |
//PayPal case | |
String userName = null; | |
String password = null; | |
//get user name and password | |
if (type == 2){ | |
System.out.println("Please enter your PayPal username: "); | |
userName = userInput.next(); | |
System.out.println("Please enter your PayPal password: "); | |
password = userInput.next(); | |
//creating PayPal object | |
Payment payPal1 = new PayPal(userName, password, order1.getTotalPrice()); | |
//authorising PayPal data. Exit programme if payment is not authorised. | |
if (!payPal1.authorize(type)){ | |
System.exit(0); | |
} | |
} | |
//card case | |
String cardNumber = null; | |
String verificationNumber = null; | |
String expirationDate = null; | |
//get card data | |
if (type == 0 || type == 1){ | |
System.out.println("Please enter your card number without spaces: "); | |
cardNumber = userInput.next(); | |
System.out.println("Please enter your verification number: "); | |
verificationNumber = userInput.next(); | |
System.out.println("Please enter your expiration date in the format DDMMYY: "); | |
expirationDate = userInput.next(); | |
//creating card object | |
Payment card1 = new Card(cardNumber, verificationNumber, expirationDate, order1.getTotalPrice()); | |
//authorising card data. Exit programme if payment is not authorised. | |
if (!card1.authorize(type)){ | |
System.exit(0); | |
} | |
} | |
//BEGIN CONFIRMATION - Ann | |
//create a confirmation | |
Confirmation confirmation1 = new Confirmation(); | |
//print booking number | |
System.out.println("\nYour payment has been confirmed. Your booking number is " + | |
confirmation1.getBookingNumber() + ".\nPlease keep this number to pick up your tickets at the counter.\n"); | |
//Create an output with booking number, price, number of seats, movie info | |
confirmation1.writeConfirmation(order1.getTotalPrice(), | |
order1.getNumberOfTickets(), selectedMovie.getMovieName(), selectedTime); | |
//printing confirmation on-screen | |
confirmation1.readConfirmation(); | |
//ending main method | |
} | |
//DECLARING METHODS USED FOR MOVIE SECTION - Yasamin | |
//Declaring the promtUserMovieSelection method | |
public static Movie promtUserMovieSelection(Movie[] movies, Scanner scanner) throws IOException { | |
System.out.println("\n Please choose a movie "); | |
// make an index of the movies you can choose from | |
for(int i = 0; i < movies.length; i++) { | |
System.out.println((i+1) + ": " + movies[i].getMovieName()); | |
} | |
System.out.println(""); | |
System.out.print("\n Enter the number of the movie you like to watch: "); | |
// while(true) loop runs until a "return" statement will stop it (so user HAS to choose a movie) | |
while(true) { | |
try { | |
int i = scanner.nextInt(); | |
// number the user chooses has to be between 1 and movies-length (3) | |
if(i < 1 || i > movies.length) { | |
// if it is not, error message will show | |
System.err.println("Number has to be between 1 and " + movies.length); | |
} | |
else { | |
// if it is between 1-3 it will print out the chosen number | |
System.out.print(i); | |
return movies[i-1]; | |
} | |
} | |
// This exception is thrown by the scanner upon calling .nextInt() if the entered value is not an integer | |
catch(InputMismatchException e) { | |
System.err.println("\n Please try again. It has to be a whole Integer"); | |
scanner.next(); | |
} | |
} | |
} | |
//declaring the promtUserTimeSelection | |
public static String promtUserTimeSelection(String[] timeSlots, Scanner scanner) throws IOException { | |
System.out.println("\n Please choose a time "); | |
//prints options | |
for(int i = 0; i < timeSlots.length; i++) { | |
System.out.println((i+1) + ": " + timeSlots[i]); | |
} | |
System.out.println(""); | |
System.out.print("\n Enter the number of the timeslot: "); | |
// This loop will run until the user has selected a movie. | |
while (true){ | |
try { | |
int i = scanner.nextInt(); | |
// Number has to be between 1 and number of time slots for the movie (timeslots.length) | |
if(i < 1 || i > timeSlots.length) { | |
System.err.println("Number has to be between 1 and " + timeSlots.length); | |
} | |
else { | |
System.out.print(i); | |
return timeSlots[i-1]; | |
} | |
} | |
catch(InputMismatchException e){ | |
System.err.println("Please try again. It has to be a whole Integer"); | |
scanner.next(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment