Wednesday, December 14, 2011

Java Ticketing System Sample

import java.util.Scanner;
import java.text.DecimalFormat;
public class TicketingWithPrice{

public static void main(String []args){

//**Variables
int Twin_Seat=0, Normal_Seat = 5, Menu_Selection,Menu_Selection1,Movie_Selection,ShowTime_Selection;
double PriceOfTwinSeat=12.00,PriceOfNormalSeat=10.00;

//***Decimal format
DecimalFormat myFormatter = new DecimalFormat("00.00");
String output1 = myFormatter.format(PriceOfTwinSeat);
String output2 = myFormatter.format(PriceOfNormalSeat);

Scanner keyboard = new Scanner(System.in); ///***scanner to accept keyboard input



for ( ; ; ) { ///**infinite loop for menu

///now showing movies detais

System.out.println("\nWelcome to 'ComeWatch a New Cinema' Ipoh, Perak\n");
System.out.println("*******************NOW SHOWING MOVIES********************\n");
System.out.println("1. ALAMAK TOYOL! at 12.00PM\n2. IMMORTALS at 03.00PM\n3. REAL STEEL at 06.00PM");
System.out.println("4. 7AAM ARIVU at 09.00PM\n5. VELAYUTHAM at 12.00AM\n");
System.out.println("Please select a movie do you wish to watch.....");
Movie_Selection = keyboard.nextInt();
System.out.println("Your movie selection is: " + Movie_Selection+"\n");

///case statement for movie selection
String Movie_SelectionString;
switch (Movie_Selection) {
case 1: Movie_SelectionString ="ALAMAK TOYOL! at 12.00PM";break;
case 2: Movie_SelectionString ="IMMORTALS at 03.00PM";break;
case 3: Movie_SelectionString ="REAL STEEL at 06.00PM";break;
case 4: Movie_SelectionString ="7AAM ARIVU at 09.00PM";break;
case 5: Movie_SelectionString ="VELAYUTHAM at 12.00AM";break;
default: Movie_SelectionString ="Invalid movie selection"; break;

}


while(Twin_Seat<5 || Normal_Seat<10){ ///***Condition

System.out.println("\nWelcome to 'ComeWatch a New Cinema' Ipoh, Perak\n");
System.out.println("We are showing "+Movie_SelectionString);
System.out.println("Please make a selection from the menu to continue....");
System.out.println("If you wish to watch another movie please refer to the 5th menu.");
System.out.println("Other movie will be shown after 3 hours according to the schedule.\n");

///***MENU***///
System.out.println("~~~~~~~~~~~~~~~~~MENU~~~~~~~~~~~~~~~~~"); ///menu selection
System.out.println("Please type: '1' for Twin Seat");
System.out.println("Please type: '2' for Normal Seat");
System.out.println("Please type: '3' to Exit");
System.out.println("Please type: '4' for Ticket Price Details");
System.out.println("Please type: '5' for Show Details\n");

Menu_Selection = keyboard.nextInt();
System.out.println("You had choosen: "+ Menu_Selection+"\n");

if(Menu_Selection == 1){ ///***Menu 1 Condition
if(Twin_Seat<5){
Twin_Seat++;
System.out.println("ComeWatch a New Cinema>>(IPOH, PERAK)");
System.out.println("You are in the twin seat category");
System.out.println("Enjoy watching " +Movie_SelectionString);
System.out.println("Your seat number is: "+ Twin_Seat);
int empty = 5-Twin_Seat;
System.out.println("The total number of empty Twin Seat (is/are): " + empty);
System.out.println("Total Cash Payment: RM " +output1);
}
else if(Normal_Seat < 10){
System.out.println("The twin Seat are fully sold out but the normal seat are still available");
System.out.println("Do prefer to get the Normal Seat?");
System.out.println("If 'YES' press 1 or press 2 for 'NO'");
Menu_Selection1 = keyboard.nextInt();

if(Menu_Selection1 ==1){ ///***internal menu condition
Normal_Seat++;
System.out.println("ComeWatch a New Cinema>>(IPOH, PERAK)");
System.out.println("You are in the normal seat category");
System.out.println("Enjoy watching " +Movie_SelectionString);
System.out.println("Your seat number is: "+ Twin_Seat);
System.out.println("Your seat number is : " + Normal_Seat);
int emptyNormalseat = 10 - Normal_Seat;
System.out.println("The total number of empty Normal Seat (is/are): " + emptyNormalseat);
System.out.println("Total Cash Payment: RM " +output2);
}
else
System.out.println("\nNext show in 3 hours time.");
}
}
else if(Menu_Selection == 2){ ///***Menu 2 Condition
if(Normal_Seat < 10){
Normal_Seat++;
System.out.println("ComeWatch a New Cinema>>(IPOH, PERAK)");
System.out.println("You are in the normal seat category");
System.out.println("Enjoy watching " +Movie_SelectionString);
System.out.println("Your seat number is: "+ Twin_Seat);
System.out.println("Your seat number is : " + Normal_Seat);
int emptyNormalseat = 10 - Normal_Seat;
System.out.println("The total number of empty Normal Seat (is/are): " + emptyNormalseat);
System.out.println("Total Cash Payment: RM " +output2);
}
else if(Twin_Seat < 5){
System.out.println("The normal Seat are fully sold out but the twin seat are still available");
System.out.println("Do prefer to get the Normal Seat?");
System.out.println("If 'YES' press 1 or press 2 for 'NO'");
Menu_Selection1 = keyboard.nextInt();

if(Menu_Selection1 ==1){ ///***internal menu condition

Twin_Seat++;
System.out.println("ComeWatch a New Cinema>>(IPOH, PERAK)");
System.out.println("You are in the twin seat category");
System.out.println("Enjoy watching " +Movie_SelectionString);
System.out.println("Your seat number is: "+ Twin_Seat);
System.out.println("Your seat number is: "+ Twin_Seat);
int emptyTwinseat = 5 - Twin_Seat;
System.out.println("The total number of empty Twin Seat (is/are): " + emptyTwinseat);
System.out.println("Total Cash Payment: RM " +output1);
}
else
System.out.println("\nNext show in 3 hours time.");
}
}

else if(Menu_Selection > 3 && Menu_Selection != 4 && Menu_Selection != 5){ ///***Menu Condition for invalid key
System.out.println("INVALID KEY");
}
else if(Menu_Selection == 3){ ///***Menu 3 Condition
System.out.println("THANK YOU AND HAVE A NICE DAY");
////***Nested Loop Break Method
while(true){
while(true){
break;
}
}

}
else if(Menu_Selection == 4){ ///***Menu 4 Condition
System.out.println("Twin Seat = RM 12\nNormal Seat = RM 10.00\n");
}

else if(Menu_Selection == 5){
System.out.println("1. ALAMAK TOYOL! at 12.00PM\n2. IMMORTALS at 03.00PM\n3. REAL STEEL at 06.00PM");
System.out.println("4. 7AAM ARIVU at 09.00PM\n5. VELAYUTHAM at 12.00AM\n");
}
}
System.out.println("\n\nThe hall is now full."); ///msg after the hall had fully sold
break;
}
}
}