Professional Documents
Culture Documents
Computer Project Movie Ticketing System
Computer Project Movie Ticketing System
BlueJ is an integrated development environment (IDE) for the Java programming language,
developed mainly for educational purposes, but also suitable for small-scale software development.
BlueJ was developed to support the learning and teaching of object-oriented programming, and its
design differs from other development environments as a result. The main screen graphically shows the
class structure of an application under development (in an UML-like diagram), and objects can be
interactively created and tested. This interaction facility, combined with a clean, simple user interface,
allows easy experimentation with objects under development. Object-oriented concepts (classes, objects,
communication through method calls) are represented visually and in its interaction design in the
interface.
1. Data types are predefined by the Java language.
2. Predefined data types are reserved keyword so we cannot use them as variable
name inside program/application.
5. All Primitive Data Types have respective Wrapper Classes i.e. Integer is wrapper
class for primitive type int.
Data Types:
Type Contains Default Size
Integer Data Type can have 4 types of Values these are listed
below in the table -
Name Width Range
long 64 –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
42
10000
−233000
Example: Declaring Integer Variable in Java
Programming
Class IntDemo
{
Public static void main(String args[])
{
int number=0;
System.out.println("Number: " +number);
}
}
Explanation:
1. Primitive Variable can be declared using “int” keyword.
2. Though Integer contain default Initial Value as 0, still we have assign 0 to show
assignment in Java.
4. Integer is converted into String internally and then two strings are concatenated.
float Variables of this type can have values from -3.4E38 (-3.4 * 1038) to +3.4E38
(+3.4 * 1038) and occupy 4 bytes in memory. Values are represented with
approximately 7 decimal digits accuracy
double Variables of this type can have values from -1.7E308 (-1.7 * 10308) to
+1.7E308 (+1.7 * 10308) and occupy 8 bytes in memory. Values are
represented with approximately 17 decimal digits accuracy. The smallest non-
zero value that you can have is roughly (4.9 * 10–324).
We have assigned integer value to the Double . (i.e we are assigning lower
value of inside bigger variable , no need to typecast )
double keyword is used to declare double variable.
What is Unicode ?
Unicode defines a fully international character set that can represent all of the
characters found in all human languages.
ch = 'M';
System.out.println("Character is : " + ch);
}
}
Output :
Character is : M
Output :
ch1 and ch2: X Y
ch1 = 'P';
System.out.println("ch1 contains " + ch1);
Output :
ch1 contains P
ch1 is now Q
boolean b1,b2,b3;
Output:
true
false
false
b = true;
if(b == true)
{
System.out.println("I am True");
}
}
boolean b;
if(b)
{
System.out.println("10 > 6");
}
}
}
We can use boolean value to hold the result Comparison operators. Here 10 >
6 therefore true will be stored in boolean variable
In Java a reference data type is a variable that can contain the reference or an
address of dynamically created object. These type of data type are not predefined
like primitive data type. The reference data types
are arrays, classes and interfaces that are made and handle according to a
programmer in a java program which can hold the three kind of values as:
array type
// Points to an array instance
class type
// Points to an object or a class instance
interface type
// Points to an object and a method, which is
implemented to the corresponding interface
class type:
class Fruit {
fColor(){....}
fSize(){....}
};Fruit mango;
Fruit banana;
...
In the given example the Fruit is a class that has the reference variables as mango &
banana through which we can call
the behaviors associated with that class as mango.fColor(); within the main method of
the super class.
Array Type:
An array is a special kind of object that contains values called elements. The java
array enables the user to store the values of the same type in contiguous memory
allocations. The elements in an array are identified by an integer index which initially
starts from 0 and ends with one less than number of elements available in the array.
All elements of an array must contain the same type of value i.e. if an array is a type of
integer then all the elements must be of integer type. It is areference data
type because the class named as Array implicitly extendsjava.lang.Object. The
syntax of declaring the array is shown as:
DataType [] variable1,
variable2, .......variableN;
For example:
In the first statement, an array variable "a" is declared of integer data type that holds
the memory spaces according to the size of int. The index of the array starts
from a[0] and ends with a[9]. Thus, the integer value can be assigned for each or a
particular index position of the array.
In the second statement, the array "b" is declared of string data type that has the
enough memory spaces to directly holds the three string values. Thus each value is
assigned for each index position of the array.
Interface Type:
Runnable r;
r = new
Thread();
There are two types of decision making statements in Java. They are:
if statements
switch statements
The if Statement:
A if statement consists of a Boolean expression
followed by one or more statements.
Syntax:
The syntax of a if statement is:
if(Boolean_expression)
{
//Statements will execute if the Boolean
expression is true
}
Example:
public class Test
{
if( x < 20 )
{
System.out.print("This is if statement");
}
}
}
Output:
This is if statement
if(Boolean_expression)
{
//Executes when the Boolean expression is
true
}else
{
//Executes when the Boolean expression is
false
}
Example:
public class Test {
if( x < 20 ){
System.out.print("This is if statement");
}else{
System.out.print("This is else statement");
}
}
}
An if can have zero or one else's and it must come after any else if's.
An if can have zero to many else if's and they must come before the else.
Once an else if succeeds, none of the remaining else if's or else's will be tested.
Syntax:
The syntax of an if...else…if is:
if(Boolean expression 1)
{
//Executes when the Boolean expression 1 is true
}
else if(Boolean expression 2)
{
//Executes when the Boolean expression 2 is true
}
else if(Boolean expression 3)
{
//Executes when the Boolean expression 3 is true
}
else
{
//Executes when the none of the above condition is true.
}
Example:
public class Test
{
if( x == 10 )
{
System.out.print("Value of X is 10");
}
else if( x == 20 )
{
System.out.print("Value of X is 20");
}
else if( x == 30 )
{
System.out.print("Value of X is 30");
}
else
{
System.out.print("This is else statement");
}
}
}
Value of X is 30
Syntax:
The syntax for a nested if...else is as follows:
if(Boolean_expression 1)
{
//Executes when the Boolean expression 1 is true
if(Boolean_expression 2)
{
//Executes when the Boolean expression 2 is true
}
}
You can nest else if...else in the similar way as we have nested if statement.
Example:
public class Test {
if( x == 30 ){
if( y == 10 ){
System.out.print("X = 30 and
Y = 10");
}
}
}
}
X = 30 and Y = 10
switch(expression)
{
case value :
//Statements
break; //optional
case value :
//Statements
break; //optional
//You can have any number of case statements.
default : //Optional
//Statements
}
The variable used in a switch statement can only be a byte, short, int, or char.
You can have any number of case statements within a switch. Each case is followed by
the value to be compared to and a colon.
The value for a case must be the same data type as the variable in the switch and it
must be a constant or a literal.
A stream can be defined as a sequence of data. The InputStream is used to read data
from a source and the OutputStream is used for writing data to a destination.
Java does provide strong, flexible support for I/O as it relates to files and networks.
Each time that read( ) is called, it reads a character from the input stream and returns it
as an integer value. It returns .1 when the end of the stream is encountered. As you can
see, it can throw an IOException.
The following program demonstrates read( ) by reading characters from the console
until the user types a "q":
The following program demonstrates BufferedReader and the readLine( ) method. The
program reads and displays lines of text until you enter the word "end":
Following constructor takes a file name as a string to create an input stream object to
read the file.:
Following constructor takes a file object to create an input stream object to read the file.
First we create a file object using File() method as follows:
Here are two constructors which can be used to create a FileOutputStream object.
Following constructor takes a file name as a string to create an input stream object to
write the file:
Following constructor takes a file object to create an output stream object to write the
file. First, we create a file object using File() method as follows:
Example:
Following is the example to demonstrate InputStream and OutputStream:
import java.io.*;
try{
byte bWrite [] = {11,21,3,40,5};
OutputStream os = new FileOutputStream("test.txt");
for(int x=0; x < bWrite.length ; x++){
os.write( bWrite[x] ); // writes the bytes
}
os.close();
The above code would create file test.txt and would write given numbers in binary
format. Same would be output on the stdout screen.
An exception is a problem that arises during the execution of a program. An exception
can occur for many different reasons, including the following:
A network connection has been lost in the middle of communications or the JVM has
run out of memory.
Some of these exceptions are caused by user error, others by programmer error, and
others by physical resources that have failed in some manner.
Categories of exceptions:
Checked exceptions: A checked exception is an exception that is typically a user error
or a problem that cannot be foreseen by the programmer. For example, if a file is to be
opened, but the file cannot be found, an exception occurs. These exceptions cannot
simply be ignored at the time of compilation.
Runtime exceptions: A runtime exception is an exception that occurs that probably
could have been avoided by the programmer. As opposed to checked exceptions,
runtime exceptions are ignored at the time of compilation.
Errors: These are not exceptions at all, but problems that arise beyond the control of
the user or the programmer. Errors are typically ignored in your code because you can
rarely do anything about an error. For example, if a stack overflow occurs, an error will
arise. They are also ignored at the time of compilation.
Catching Exceptions:
A method catches an exception using a combination of the try and catch keywords. A
try/catch block is placed around the code that might generate an exception. Code within
a try/catch block is referred to as protected code, and the syntax for using try/catch
looks like the following:
try
{
//Protected code
}catch(ExceptionName e1)
{
//Catch block
}
A catch statement involves declaring the type of exception you are trying to catch. If an
exception occurs in protected code, the catch block (or blocks) that follows the try is
checked. If the type of exception that occurred is listed in a catch block, the exception is
passed to the catch block much as an argument is passed into a method parameter.
Example:
The following is an array is declared with 2 elements. Then the code tries to access the
3rd element of the array which throws an exception.
try
{
//Protected code
}catch(ExceptionType1 e1)
{
//Catch block
}catch(ExceptionType2 e2)
{
//Catch block
}catch(ExceptionType3 e3)
{
//Catch block
}
The previous statements demonstrate three catch blocks, but you can have any number
of them after a single try. If an exception occurs in the protected code, the exception is
thrown to the first catch block in the list. If the data type of the exception thrown
matches ExceptionType1, it gets caught there. If not, the exception passes down to the
second catch statement. This continues until the exception either is caught or falls
through all catches, in which case the current method stops execution and the
exception is thrown down to the previous method on the call stack.
Example:
Here is code segment showing how to use multiple try/catch statements.
try
{
file = new FileInputStream(fileName);
x = (byte) file.read();
}catch(IOException i)
{
i.printStackTrace();
return -1;
}catch(FileNotFoundException f) //Not valid!
{
f.printStackTrace();
return -1;
}
A method can declare that it throws more than one exception, in which case the
exceptions are declared in a list separated by commas. For example, the following
method declares that it throws a RemoteException and an InsufficientFundsException:
import java.io.*;
public class className
{
public void withdraw(double amount) throws RemoteException,
InsufficientFundsException
{
// Method implementation
}
//Remainder of class definition
}
Using a finally block allows you to run any cleanup-type statements that you want to
execute, no matter what happens in the protected code.
A finally block appears at the end of the catch blocks and has the following syntax:
try
{
//Protected code
}catch(ExceptionType1 e1)
{
//Catch block
}catch(ExceptionType2 e2)
{
//Catch block
}catch(ExceptionType3 e3)
{
//Catch block
}finally
{
//The finally block always executes.
}
Example:
public class ExcepTest{
It is not compulsory to have finally clauses when ever a try/catch block is present.
The try block cannot be present without either catch clause or finally clause.
Any code cannot be present in between the try, catch, finally blocks.
The Java Project Program
(Movie Ticketing System)
import java.io.*;
public class movies
{
static double bill;
static int c,type,d,flag;
static int e,type1,f;
static int g,type2,h; //Initialising all the required variables
static int i,type3,j;
static int quan;
static String l,n[],k;
static int m;
static String s,s1,s2,s3;
public static void main(String [] args)throws IOException
{
String a,b;String ch="";
String n[]=new String[4];
n[0]="burger";
n[1]="nachos";
n[2]="coke";
n[3]="popcorn";
BufferedReader buf=new BufferedReader(new
InputStreamReader(System.in));
do
{
System.out.println("--------------- WELCOME TO FUN CINEMAS ONLINE
BOOKING COUNTER ---------------");
System.out.println(" PLEASE SELECT THE MOVIE YOU WOULD LIKE TO
WATCH: ");
System.out.println("\n");
System.out.println("1. IRON MAN 3 ");
System.out.println("2. FAST AND FURIOUS 6 ");
System.out.println("3. GO GOA GONE ");
//Here the movie is being selected
System.out.println("4. MAN OF STEEL ");
System.out.println("\n");
System.out.println("TYPE THE NAME OF THE MOVIE YOU WANT TO WATCH IN CAPILTAL
LETTERS");
try
{
ch=buf.readLine(); //an expected error that the user enters
something else instead of the movie
}
catch(IOException e1)
{
System.out.println("Movie not running"); //handling of the exception
}
if(ch.equalsIgnoreCase("IRON MAN 3"))
{
System.out.println("\nPROCESSING YOUR REQUEST");
for(int z=0;z<1000000000;z++)
{
}
System.out.println("\f");
IM3();
}
if(ch.equalsIgnoreCase("FAST AND FURIOUS 6"))
{
System.out.println("\nPROCESSING YOUR REQUEST");
for(int z=0;z<1000000000;z++)
{
}
System.out.println("\f");
//calling of the function corresponding to the movie selected
FAF6();
}
if(ch.equalsIgnoreCase("GO GOA GONE"))
{
System.out.println("\nPROCESSING YOUR REQUEST");
for(int z=0;z<1000000000;z++)
{
}
System.out.println("\f");
GGG();
}
if(ch.equalsIgnoreCase("MAN OF STEEL"))
{
System.out.println("\nPROCESSING YOUR REQUEST");
for(int z=0;z<1000000000;z++)
{
}
System.out.println("\f");
MOS();
}
System.out.println("\n\n");
System.out.println("DO YOU WANT TO BOOK SOME SNACKS:");
System.out.println("\n\n");
System.out.println("TYPE 'Y' FOR YES OR PRESS ANY OTHER KEY");
a=buf.readLine();
System.out.println("\nPROCESSING YOUR REQUEST");
for(int z=0;z<1000000000;z++)
{
}
System.out.println("\f");
if(a.equalsIgnoreCase("y")) //checking whether the user wants to buy
some snacks or not
{
SNACKS();
}
System.out.println("\n\n");
System.out.println("*** **** ***** COPY OF THE RECIEPT IS: ***** **** ***");
System.out.println("MOVIE: "+ch);
System.out.println("NO. OF TICKETS: "+d);
//displaying of the bill
do
{
System.out.print("THE SNACKS BOOKED ARE: ");
for(m=0;m<1;m++)
{
if(s.equalsIgnoreCase(n[m]))
{
flag=0;
System.out.print(n[m]);
break;
}
}
for(m=1;m<2;m++)
{
if(s1.equalsIgnoreCase(n[m]))
{
flag=0;
System.out.print(", "+n[m]);
break;
}
}
for(m=2;m<3;m++)
{
if(s2.equalsIgnoreCase(n[m]))
{
flag=0;
System.out.print(", "+n[m]);
break;
}
}
for(m=3;m<4;m++)
{
if(s3.equalsIgnoreCase(n[m]))
{
flag=0;
System.out.println(", "+n[m]);
break;
}
}
}while(flag!=0);
}
if(s1.equalsIgnoreCase(n[1]))
{
System.out.println("\n\n");
System.out.println("FOR NACHOS");
System.out.println("THE PRICE IS RS.100");
System.out.println("ENTER HOW MANY NACHOS DO YOU WANT TO BUY:");
try
{
quan=Integer.parseInt(buf.readLine());
}
catch(IOException e2)
{
System.out.println("INVALID ENTRY");
}
bill=bill+(quan*100);
}
if(s2.equalsIgnoreCase(n[2]))
{
System.out.println("\n\n");
System.out.println("FOR COKE");
System.out.println("THE PRICE IS RS.70");
System.out.println("ENTER HOW MANY COKE DO YOU WANT TO BUY:");
try
{
quan=Integer.parseInt(buf.readLine());
}
catch(IOException e2)
{
System.out.println("INVALID ENTRY");
}
bill=bill+(quan*70);
}
if(s3.equalsIgnoreCase(n[3]))
{
System.out.println("\n\n");
System.out.println("FOR POPCORN");
System.out.println("THE PRIC IS RS.90");
System.out.println("ENTER HOW MANY POPCORN DO YOU WANT TO BUY:");
try
{
quan=Integer.parseInt(buf.readLine());
}
catch(IOException e2)
{
System.out.println("INVALID ENTRY");
}
bill=bill+(quan*90);
}
}
}
Variable Data type Use of the variable
bill Double it stores the bill
amount
c int Stores the time
entered by the user
for the movie iron
man 3
type Int Stores the class of
the move iron man 3
d Int Stores the no. of
tickets bought for
movie iron man 3
flag Int Loop control variable
for checking the
snacks entered by
the use and
displaying them.
e Int Stores the time
entered by the user
for the movie fast
and the furious 6
type1 Int Stores the class of
the move fast and
the furious 6
f Int Stores the no. of
tickets bought for
movie fast and the
furious 6
g int Stores the time
entered by the user
for the movie go goa
gone
type2 Int Stores the class of
the move go goa
gone
h Int Stores the no. of
tickets bought for
movie go goa gone
i int Stores the time
entered by the user
for the movie man of
steel
type3 Int Stores the class of
the move man of
steel
j Int Stores the no. of
tickets bought for
movie man of steel
quan Int Stores the quantity
of snacks bought by
the user
n[] String(array) Stores the snacks
options for the user
M Int It is the loop control
variable which
compares the snack
entered by the user
with the snacks
stored in n.
s String The 1st snack
entered by the user
s1 String The 2nd snack
entered by the user
s2 String The 3rd snack
entered by the user
s3 String The 4th snack
entered by the user
a String Checks whether the
user wants to buy
any snacks or not.
b String Checks whether user
wants to buy more
tickets or not
ch String Stores the movie
entered by the user
z int Loop control variable
for the loop for
delaying the process
SCREEN 1:
--------------- WELCOME TO FUN CINEMAS ONLINE BOOKING COUNTER ---------------
PLEASE SELECT THE MOVIE YOU WOULD LIKE TO WATCH:
1. IRON MAN 3
2. FAST AND FURIOUS 6
3. GO GOA GONE
4. MAN OF STEEL
TYPE THE NAME OF THE MOVIE YOU WANT TO WATCH IN CAPILTAL LETTERS
IRON MAN 3
PROCESSING YOUR REQUEST
SCREEN 2:
---------- WHAT TIMING OF THE MOVIE IRON MAN 3 DO YOU WANT TO BOOK ----------
ENTER:
1. for 8:00 am
2. for 11:00 am
3. for 2:00 pm
4. for 5:00 pm
5. for 9:00 pm
1
WHICH CLASS WOULD YOU LIKE TO BOOK:
1.BUSSINESS
2.GOLD
3.SILVER
4.BRONZE
1
THE PRICE IS Rs.500 PER TICKET
1. BURGER
2. NACHOS
3. COKE
4. POPCORN
ENTER THE NAME OF THE SNACK IN THE ABOVE MENTIONED ORDER,
NOTE: AFTER WRITING THE NAME OF THE SSNACK HIT ENTER AND IF YOU DO NOT WANT TO BUY ANY SNACK
THEN HIT ENTER AND TYPE THE NEXT SNACK
BURGER
COKE
POPCORN
FOR BURGER
THE PRICE IS RS.80
ENTER HOW MANY BURGERS DO YOU WANT TO BUY:
5
FOR COKE
THE PRICE IS RS.70
ENTER HOW MANY COKE DO YOU WANT TO BUY:
5
FOR POPCORN
THE PRIC IS RS.90
ENTER HOW MANY POPCORN DO YOU WANT TO BUY:
2
SCREEN 4:
*** **** ***** COPY OF THE RECIEPT IS: ***** **** ***
MOVIE: IRON MAN 3
NO. OF TICKETS: 5
THE SNACKS BOOKED ARE: burger coke popcorn