Download - RAILWAY RESERVATION.doc

Transcript
Page 1: RAILWAY RESERVATION.doc

Contents:

AcknowledgementAbstract IntroductionRequirements SpecificationsDesignModules

Database Design Front End Database Connectivity With Java IDE

UML Diagrams Use Case Diagrams Class Diagrams Sequence Diagrams Component Diagrams Deployment Diagrams

Implementation Coding

TestingResults

Screen ShotsConclusionFuture ScopeReferences

1

Page 2: RAILWAY RESERVATION.doc

ABSTRACT

Designing a database for local train reservation system and trying to get an access

to the database and reserve.

This project deals with reserving tickets for the local trains which is heck these

days .So inorder to make it convenient to travel we can book tickets priorily. This makes

the travel smooth and convenient. This also helps in checking the details afterwards.

2

Page 3: RAILWAY RESERVATION.doc

INTRODUCTION

Designing a database for local train reservation system and trying to get an

access to the database and reserve.

This project deals with reserving tickets for the local trains which is heck these

days .So inorder to make it convenient to travel we can book tickets priorily. This makes

the travel smooth and convenient. This also helps in checking the details afterwards.

3

Page 4: RAILWAY RESERVATION.doc

REQUIREMENTS SPECIFICATIONS

SOFTWARE REQUIREMENTS:

Operating System – Windows XP

Java 5.0

HARDWARE REQUIREMENTS:

Computer processor- Pentium dualcore

1.2 ghz

Hard Disk-320GB

RAM-3GB

4

Page 5: RAILWAY RESERVATION.doc

DESIGN

MODULES:

DATABASE DESIGN: The tables used are

1. TRAINRESRVATION TABLE2. PASSENGER TABLE

1. TRAINRESERVATION TABLE: This table contains the details of trains Such as train name , Source Station ,Destination Station, Arrival Time, Destination Time , No.of seats .

2.PASSENGER TABLE: This table contains the details of passenger1 such as Traveler name, train name , date, source ,destination.

5

Page 6: RAILWAY RESERVATION.doc

SQL (Structured Query Language)

SQL (Structured Query Language) is a database computer language designed for managing data in relational database management systems (RDBMS), and originally based upon Relational Algebra. Its scope includes data query and update, schema creation and modification, and data access control.

The most common operation in SQL is the query, which is performed with the declarative SELECT statement. SELECT retrieves data from one or more tables, or expressions.

A query includes a list of columns to be included in the final result immediately following the SELECT keyword. An asterisk ("*") can also be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include:

The FROM clause which indicates the table(s) from which data is to be retrieved. The FROM clause can include optional JOIN subclauses to specify the rules for joining tables.

The WHERE clause includes a comparison predicate, which restricts the rows returned by the query. The WHERE clause eliminates all rows from the result set for which the comparison predicate does not evaluate to True.

The following is an example of a SELECT query that returns a list of trains available. The query retrieves all rows from the trainreservation in which the sourcr column contains a value as lingampally. The asterisk (*) in the select list indicates that all columns of the trainreservation table should be included in the result set.

SELECT * FROM trainreservation WHERE source=”lingampally”;

Data manipulation

The Data Manipulation Language (DML) is the subset of SQL used to add, update and delete data:

INSERT adds rows (formally tuples) to an existing table, e.g.,:

insert into trainreservation("LF1","Hyd","lingampally",20,10.30,11.30);

insert into passenger("xyz","LF1",x,21-03-10); UPDATE modifies a set of existing table rows, e.g.,:

6

Page 7: RAILWAY RESERVATION.doc

UPDATE passenger SET noofseats=2 WHERE psgname = 'sss'; DELETE removes existing rows from a table, e.g.,:

DELETE FROM trainreservation WHERE psgname = 'sss';

Transaction controls

Transactions, if available, DML operations:

COMMIT causes all data changes in a transaction to be made permanent.

ROLLBACK causes all data changes since the last COMMIT or ROLLBACK to be discarded, leaving the state of the data as it was prior to those changes.

Once the COMMIT statement completes, the transaction's changes cannot be rolled back.

Commit;

Data definition

The Data Definition Language (DDL) manages table and index structure. The most basic items of DDL are the CREATE, ALTER, RENAME, DROP and TRUNCATE statements:

CREATE creates an object (a table, for example) in the database.

Eg: create table trairnreservation(tname varchar(20),source varchar(20),Destination varchar(20),Noofseats number(3),arrival number(12,2),departure number(12,2));

Eg:create table passenger(psgname varchar(20),tname varchar(20),Noofseats number(3),date varchar(20));

DROP deletes an object in the database, usually irretrievably. ALTER modifies the structure of an existing object in various ways—for example,

adding a column to an existing table.

Data control

The Data Control Language (DCL) authorizes users and groups of users to access and manipulate data. Its two main statements are:

GRANT authorizes one or more users to perform an operation or a set of operations on an object.

REVOKE eliminates a grant, which may be the default grant.

APPLET

7

Page 8: RAILWAY RESERVATION.doc

An applet is any small application that performs one specific task; sometimes running within the context of a larger program, perhaps as a plugin.[1][2] However, the term typically also refers to programs written in the Java programming language which are included in an HTML page

All applets have the following four methods:

public void init();public void start();public void stop();public void destroy();

They have these methods because their superclass, java.applet.Applet, has these methods. (It has others too, but right now I just want to talk about these four.)

In the superclass, these are simply do-nothing methods. For example,

public void init() {}

Subclasses may override these methods to accomplish certain tasks at certain times. For instance, the init() method is a good place to read parameters that were passed to the applet via <PARAM> tags because it's called exactly once when the applet starts up. However, they do not have to override them. Since they're declared in the superclass, the Web browser can invoke them when it needs to without knowing in advance whether the method is implemented in the superclass or the subclass. This is a good example of polymorphism.

The init() method is called exactly once in an applet's life, when the applet is first loaded. It's normally used to read PARAM tags, start downloading any other images or media files you need, and set up the user interface. Most applets have init() methods.

The start() method is called at least once in an applet's life, when the applet is started or restarted. In some cases it may be called more than once. Many applets you write will not have explicit start()methods and will merely inherit one from their superclass. A start() method is often used to start any threads the applet will need while it runs.

The stop() method is called at least once in an applet's life, when the browser leaves the page in which the applet is embedded. The applet's start() method will be called if at some later point the browser returns to the page containing the applet. In some cases the stop() method may be called multiple times in an applet's life. Many applets you write will not have explicit stop()methods and will merely inherit one from their superclass. Your applet should use the stop() method to pause any running threads. When your applet is stopped, it should not use any CPU cycles.

The destroy() method is called exactly once in an applet's life, just before the browser unloads the applet. This method is generally used to perform any final clean-up. For example, an applet that stores state on the server might send some data back to the server

8

Page 9: RAILWAY RESERVATION.doc

before it's terminated. many applets will not have explicit destroy() methods and just inherit one from their superclass.

For example, in a video applet, the init() method might draw the controls and start loading the video file. The start() method would wait until the file was loaded, and then start playing it. The stop() method would pause the video, but not rewind it. If the start() method were called again, the video would pick up where it left off; it would not start over from the beginning. However, if destroy() were called and then init(), the video would start over from the beginning.

In the JDK's appletviewer, selecting the Restart menu item calls stop() and then start(). Selecting the Reload menu item calls stop(), destroy(), and init(), in that order. (Normally the byte codes will also be reloaded and the HTML file reread though Netscape has a problem with this.)

The applet start() and stop() methods are not related to the similarly named methods in the java.lang.Thread class.

Your own code may occasionally invoke start() and stop(). For example, it's customary to stop playing an animation when the user clicks the mouse in the applet and restart it when they click the mouse again.

Your own code can also invoke init() and destroy(), but this is normally a bad idea. Only the environment should call init() and destroy().

Java uses the standard, two-dimensional, computer graphics coordinate system. The first visible pixel in the upper left-hand corner of the applet canvas is (0, 0). Coordinates increase to the right and down.

GRAPHIC OBJECTS:In Java all drawing takes place via a Graphics object. This is an instance of the class java.awt.Graphics.

Initially the Graphics object you use will be the one passed as an argument to an applet's paint() method. Later you'll see other Graphics objects too. Everything you learn today about drawing in an applet transfers directly to drawing in other objects like Panels, Frames, Buttons, Canvases and more.

Each Graphics object has its own coordinate system, and all the methods of Graphics including those for drawing Strings, lines, rectangles, circles, polygons and more. Drawing in Java starts with particular Graphics object. You get access to the Graphics object through the paint(Graphics g) method of your applet. Each draw method call will look like g.drawString("Hello World", 0, 50) where g is the particular Graphics object with which you're drawing.

Load image:Image img = this.getImage(new URL("http://www.prenhall.com/logo.gif"));

9

Page 10: RAILWAY RESERVATION.doc

The getImage() method is provided by java.applet.Applet. The URL class is provided by java.net.URL. Be sure to import it.

Color is a class in the AWT. Individual colors like red or mauve are instances of this class, java.awt.Color. Be sure to import it if you want to use other than the default colors. You create new colors using the same RGB triples that you use to set background colors on web pages. However you use decimal numbers instead of the hex values used by HTML's bgcolor attribute. For example medium gray is Color(127, 127, 127). Pure white is Color(255, 255, 255). Pure red is (255, 0, 0) and so on. As with any variable you should give your colors descriptive names. For instance

Color medGray = new Color(127, 127, 127);Color cream = new Color(255, 231, 187);Color lightGreen = new Color(0, 55, 0);

A few of the most common colors are available by name. These are

Color.black Color.blue Color.cyan Color.darkGray Color.gray Color.green Color.lightGray Color.magenta Color.orange Color.pink Color.red Color.white Color.yellow

Color oldColor = g.getColor();g.setColor(Color.pink);g.drawString("This String is pink!", 50, 25);g.setColor(Color.green);g.drawString("This String is green!", 50, 50);g.setColor(oldColor);

Choosing a font face is easy. First you create a new Font object. Then you call g.setFont(Font f). To instantiate a Font object use this constructor:

public Font(String name, int style, int size)

name is the name of the font family, e.g. "Serif", "SansSerif", or "Mono".

10

Page 11: RAILWAY RESERVATION.doc

size is the size of the font in points. In computer graphics a point is considered to be equal to one pixel. 12 points is a normal size font. 14 points is probably better on most computer displays. Smaller point sizes look good on paper printed with a high resolution printer, but not in the lower resolutions of a computer monitor.

style is an mnemonic constant from java.awt.Font that tells whether the text will be bold, italic or plain. The three constants are Font.PLAIN, Font.BOLD, and Font.ITALIC. The program below prints each font in its own face and 14 point bold.

A basic example using the java.applet package

The following example is made simple enough to illustrate the essential use of Java applets through its java.applet package. It also uses classes from the Java Abstract Window Toolkit (AWT) for producing actual output (in this case, the "Hello, world!" message).

import java.applet.Applet;import java.awt.*; // Applet code for the "Hello, world!" example.// This should be saved in a file named as "HelloWorld.java".public class HelloWorld extends Applet { // This method is mandatory, but can be empty (i.e., have no actual code). public void init() { } // This method is mandatory, but can be empty. public void stop() { } // Print a message on the screen (x=20, y=10). public void paint(Graphics g) { g.drawString("Hello, world!", 20,10); }}

For compilation, this code is saved on a plain-ASCII file with the same name as the class and .java extension, i.e. HelloWorld.java. The resulting HelloWorld.class applet should be installed on the web server and is invoked within an HTML page by using an <APPLET> or a <SCRIPT> tag. For example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><TITLE>HelloWorld_example.html</TITLE></HEAD>

11

Page 12: RAILWAY RESERVATION.doc

<BODY><H1>A Java applet example</H1><P>Here it is: <APPLET code="HelloWorld.class" WIDTH="200" HEIGHT="40">This is where HelloWorld.class runs.</APPLET></P></BODY></HTML>

Displaying the HelloWorld_example.html page from a Web server, the result should look as this:

A Java applet example

Here it is: Hello, world!

To minimize download time, applets are usually delivered in a form of compressed zip archive (having jar extension). If all needed classes (only one in our case) are placed in compressed archive example.jar, the embedding code would look differently:

<P>Here it is: <APPLET code="HelloWorld" WIDTH="200" HEIGHT="40" ARCHIVE="example.jar">This is where HelloWorld.class runs.</APPLET></P>

Advantages

A Java applet can have any or all of the following advantages:

It is simple to make it work on Linux, Windows and Mac OS i.e. to make it cross platform. Applets are supported by most web browsers

The same applet can work on "all" installed versions of Java at the same time, rather than just the latest plug-in version only. However, if an applet requires a later version of the JRE the client will be forced to wait during the large download.

Most web browsers cache applets, so will be quick to load when returning to a web page. Applets also improve with use: after a first applet is run, the JVM is already running and starts quickly (JVM will need to restart each time the browser starts fresh).

It can move the work from the server to the client, making a web solution more scalable with the number of users/clients

If standalone program (like Google Earth) talks to the web server, that server normally needs to support also previous versions as the user may not keep it always updated. Differently, the browser updates the applet so there is no need to support the legacy versions. Only due configuration mistakes the applet may get stuck in the cache and have issues when new versions come out.

The applet naturally supports the changing user state like figure positions on the chessboard.

Developers can develop and debug an applet direct simply by creating a main routine (either in the applet's class or in a separate class) and call init() and start() on the

12

Page 13: RAILWAY RESERVATION.doc

applet, thus allowing for development in their favorite J2SE development environment. All one has to do after that is re-test the applet in the appletviewer program or a web browser to ensure it conforms to security restrictions.

An untrusted applet has no access to the local machine and can only access the server it came from. This makes such applet much safer to run than standalone executable that it could replace. However signed applet can have full access to the machine it is running on if the user agrees.

Disadvantages

A Java applet may have any of the following disadvantages:

It requires the Java plug-in. Some organizations only allow software installed by the administrators. As a result,

some users can only view applets that are important enough to contact the administrator asking to install the Java plug-in.

As with any client side scripting, security restrictions may make difficult or even impossible for untrusted applet to achieve the desired goals.

Some applets require a specific JRE. This is discouraged [22]. If applet requires newer or specific JRE than available on the system, the user running

it first time will need to wait for the large JRE download to complete. Java automatic installation or update may fail if proxy is used to access the web. This

makes applet with specific requirements impossible to run unless Java is manually updated. Java automatic updater that is part of Java installation also may be complex to configure if it must work through proxy.

Unlike the older applet tag, the object tag needs workarounds to write a cross-browser HTML.

DATABASE CONNECTIVITY:

Java Database Connectivity (JDBC) provides Java developers with a standard API that is used to access databases, regardless of the driver and database product. To use JDBC, you'll need at least JDK 1.1, a database, and a JDBC driver. Installing the first two should be straightforward, but finding a JDBC driver requires a little more effort. JDBC presents a uniform interface to databases - change vendors and your applications only need to change their driver.

There are plenty of drivers now for JDBC that support popular databases. If you can use a JDBC driver that works specifically for your database, then that's great! If not, don't worry - Sun provides a driver that is compatible with ODBC, so you should be able to connect to any ODBC compliant database. The JDBC to ODBC bridge comes installed as part of JDK1.1, so if this is your target platform, the driver will already be installed. You'll need to create an ODBC datasource for your database, before your Java applications can access it.

13

Page 14: RAILWAY RESERVATION.doc

Connecting to a database

In order to connect to a database, you need to perform some initialization first. Your JDBC driver has to be loaded by the Java Virtual Machine classloader, and your application needs to check to see that the driver was successfully loaded. We'll be using the ODBC bridge driver, but if your database vendor supplies a JDBC driver, feel free to use it instead.

// Attempt to load database drivertry{// Load Sun's jdbc-odbc driverClass.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();}catch (ClassNotFoundException cnfe) // driver not found{System.err.println ("Unable to load database driver");System.err.println ("Details : " + cnfe);System.exit(0);}

We try to load the JdbcOdbcDriver class, and then catch the ClassNotFoundException if it is thrown. This is important, because the application might be run on a non-Sun virtual machine that doesn't include the ODBC bridge, such as Microsoft's JVM. If this occurs, the driver won't be installed, and our application should exit gracefully.

Once our driver is loaded, we can connect to the database. We'll connect via the driver manager class, which selects the appropriate driver for the database we specify. In this case, we'll only be using an ODBC database, but in more complex applications, we might wish to use different drivers to connect to multiple databases. We identify our database through a URL. No, we're not doing anything on the web in this example - a URL just helps to identify our database.

A JDBC URL starts with "jdbc:"  This indicates the protocol (JDBC). We also specify our database in the URL. As an example, here's the URL for an ODBC datasource called 'demo'. Our final URL looks like this :

jdbc:odbc:demo

To connect to the database, we create a string representation of the database. We take the name of the datasource from the command line, and attempt to connect as user "dba", whose password is "sql".

// Create a URL that identifies databaseString url = "jdbc:odbc:" + args[0];

14

Page 15: RAILWAY RESERVATION.doc

// Now attempt to create a database connectionConnection db_connection =DriverManager.getConnection (url, "dba", "sql");

As you can see, connecting to a database doesn't take much code.

Executing database queries

In JDBC, we use a statement object to execute queries. A statement object is responsible for sending the SQL statement, and returning a set of results, if needed, from the query. Statement objects support two main types of statements - an update statement that is normally used for operations which don't generate a response, and a query statement that returns data.

// Create a statement to send SQLStatement db_statement = db_connection.createStatement();

Once you have an instance of a statement object, you can call its executeUpdate and executeQuery methods. To illustrate the executeUpdate command, we'll create a table that stores information about employees. We'll keep things simple and limit it to name and employee ID.

// Create a simple table, which stores an employee ID and namedb_statement.executeUpdate("create table employee { int id, char(50) name };");// Insert an employee, so the table contains datadb_statement.executeUpdate("insert into employee values (1, 'John Doe');");// Commit changesdb_connection.commit();

Now that there's data in the table, we can execute queries. The response to a query will be returned by the executeQuery method as a ResultSet object. ResultSet objects store the last response to a query for a given statement object. Instances of ResultSet have methods following the pattern of getXX where XX is the name of a data type. Such data types include numbers (bytes, ints, shorts, longs, doubles, big-decimals), as well as strings, booleans, timestamps and binary data.

// Execute queryResultSet result = db_statement.executeQuery("select * from employee");

// While more rows exist, print themwhile (result.next() ){// Use the getInt method to obtain emp. id

15

Page 16: RAILWAY RESERVATION.doc

System.out.println ("ID : " + result.getInt("ID"));

// Use the getString method to obtain emp. nameSystem.out.println ("Name : " + result.getString("Name"));System.out.println ();}

SAMPLE: A Java applet that use JDBC applet driver to access a databaseThis sample shows how to write a Java Applet that uses theJDBC Type 3 and 4 driver to access a DB2 database.

By default, this sample uses JDBC Type 4 driver to connect tothe "sample" database (Recommended). Run this sample using thefollowing steps:1. Create and populate the "sample" database with the followingcommand: db2sampl

2. Customize Applt.html with your server, port, user ID, andpassword. Refer to Applt.html for details.

3. Compile the program with the following command:javac Applt.java

Alternatively, you can compile the program with the followingcommand if you have a compatible make/nmake program onyour system:make/nmake Applt

4. Ensure that your working directory is accessible by your webbrowser. If it is not, copy Applt.class and Applt.html intoa directory that is accessible.

5. To use the JDBC Type 4 driver, copy sqllib\java\db2jcc.jar onWindows or sqllib/java/db2jcc.jar on UNIX, into the samedirectory as Applt.class and Applt.html.

6. To run this sample, start your web browser (which must supportJava 1.3) and load Applt.html on your client machine.You can view it locally with the following command:appletviewer Applt.html

16

Page 17: RAILWAY RESERVATION.doc

SEQUENCE DIAGRAM:

Sequence diagrams describe interactions among classes in terms of an exchange of messages over time.

17

Page 18: RAILWAY RESERVATION.doc

DEPLOYMENT DIAGRAM:

Deployment diagrams depict the physical resources in a system, including nodes, components, and connections. Component diagrams describe the organization of physical software components, including source code, run-time (binary) code, and executables.

18

Page 19: RAILWAY RESERVATION.doc

DATA FLOW DIAGRAM(DFD)

External user/ customer

receptionist

staff/flight

entry query booking request/

entry fire query

cashier

cash-transation

management administrator

19

0 LEVEL DFD

Railway TICKET

BOOKING

Page 20: RAILWAY RESERVATION.doc

ER DIAGRAM

20

Train

B

ooks

Train schedul

Passengerheaddeatils

deter

mine

s

Passenger details

Name

noofseats

Username

hid

Id

name

fnumber

Departure

Rid

Mailing address

Internal users

Upd

ate

de

termine

sArrival time

Source name

class

Flight type

Status

Bank name

cardno

cid

visit

Registered user

email

Registration date

validdate

amount

supervise

supervise

email

Phone no

password

Manages

Username

Password

Address

Email

fname

Fnumber

totalseats

Page 21: RAILWAY RESERVATION.doc

COMPONENT DIAGRAM:

Component diagrams describe the organization of physical software components, including source code, run-time (binary) code, and executables.

21

Page 22: RAILWAY RESERVATION.doc

IMPLEMENTATION:

CODING:

Javacode:

import java.sql.*;

import java.applet.*;import java.awt.event.*;import java.awt.*;import java.io.*;/*<applet code="Word_Meaning.class" width=700 height=700> </applet>*/public class Word_Meaning extends Applet implements ActionListener,TextListener,ItemListener{ Font mf,mf1; Choice tf1,tf3; TextField tf2; Choice tf4; TextField tf5; TextField tf6,tf7,tf8,tf9,tf10; Button b1,b2,b3; CheckboxMenuItem c1; List l; Label l0,l1,l2,l7,l8,l9,l3,l4,l5,l6,l10,l11; Float time1,time2,ftime,ttime; String url,s1,s2,s3,s4,str1,str2,str3,str4,str5,str6,str7,nme,src,dest,selectString; int i,seats,option; Boolean flag,option1=false,option2=false;public void init(){ setBackground(Color.cyan); l0=new Label("RAILWAY RESERVATION SYSTEM");

mf=new Font("TIMES ROMAN",Font.BOLD,30); l0.setFont(mf);

l1=new Label("Enter the train name");

22

Page 23: RAILWAY RESERVATION.doc

tf1=new Choice(); l3=new Label("Enter the Source station"); tf3=new Choice(); l4=new Label("Enter the destination station"); tf4=new Choice(); l5=new Label("Enter how many seats needed"); tf5=new TextField(30); l2=new Label("Enter Date"); tf2=new TextField(30); l10=new Label("Enter from time"); tf9=new TextField(30); l11=new Label("Enter to time"); tf10=new TextField(30); b1=new Button("Submit"); b2=new Button("Print Ticket"); b3=new Button("Check Availability"); c1=new CheckboxMenuItem("Hai"); l6=new Label("Enter Personal Details"); mf1=new Font("TIMES ROMAN",Font.BOLD,15); l6.setFont(mf1); l7=new Label("Enter name"); tf6=new TextField(30); l8=new Label("Contact Information"); tf7=new TextField(30); l9=new Label("Enter Train Details"); l9.setFont(mf1); add(l0); addNewLine(Color.cyan); add(l6); addNewLine(Color.cyan);

add(l7); add(tf6); addNewLine(Color.cyan); add(l8); add(tf7); addNewLine(Color.cyan); add(l9); addNewLine(Color.cyan);

add(l1);

23

Page 24: RAILWAY RESERVATION.doc

tf1.add("LF1"); tf1.add("FL1"); tf1.add("LH1"); tf1.add("HL1");tf1.add("LF2");tf1.add("FL2");tf1.add("LH2");tf1.add("HL2");

add(tf1); addNewLine(Color.cyan); add(l3); tf3.add("Hyderabad"); tf3.add("Lingampally");

tf3.add("Faluknama"); tf3.add("Necklace road"); tf3.add("Hitech city"); tf3.add("Begumpet"); tf3.add("Chandanagar"); tf3.add("Vidyanagar"); tf3.add("Kachiguda"); tf3.add("Malakpet"); tf3.add("Secunderabad");

add(tf3); addNewLine(Color.cyan); add(l4); tf4.add("Hyderabad"); tf4.add("Lingampally");

tf4.add("Faluknama"); tf4.add("Necklace road"); tf4.add("Hitech city"); tf4.add("Begumpet"); tf4.add("Chandanagar"); tf4.add("Vidyanagar"); tf4.add("Kachiguda"); tf4.add("Malakpet"); tf4.add("Secunderabad");

add(tf4); addNewLine(Color.cyan); add(l5); add(tf5); addNewLine(Color.cyan); add(l2); add(tf2); addNewLine(Color.cyan); add(l10); add(tf9); addNewLine(Color.cyan); add(l11); add(tf10); addNewLine(Color.cyan); add(b3); add(b1); add(b2);

tf1.addItemListener(this); tf3.addItemListener(this); tf4.addItemListener(this); tf5.addTextListener(this); tf6.addTextListener(this); tf7.addTextListener(this);

24

Page 25: RAILWAY RESERVATION.doc

tf2.addTextListener(this); tf9.addTextListener(this); tf10.addTextListener(this); b1.addActionListener(this); b3.addActionListener(this); b2.addActionListener(this); }

private void addNewLine(Color c){

Canvas line=new Canvas(); line.setSize(10000,1); line.setBackground(c); add(line);

}public void itemStateChanged(ItemEvent ie){

if(ie.getSource()==tf1) { str1=tf1.getSelectedItem(); System.out.println("tname::"+str1); }

if(ie.getSource()==tf3) {

str3=tf3.getSelectedItem(); System.out.println("source::"+str3); }

if(ie.getSource()==tf4) {

str4=tf4.getSelectedItem(); System.out.println("destination::"+str4); }

repaint();}public void paint(Graphics g){

showStatus("TRAIN"); //super.paint(g); //g.drawImage(bg,0,0,Color.white,null); if(option==1)

25

Page 26: RAILWAY RESERVATION.doc

{ if(option1==true&&flag==true) g.drawString("SUCCESSFULLY BOOKED::"+i,500,520); else g.drawString("CHECK AVAILABILITY!!!!!!",500,520); } if(option==2)

{ if(option2==true&&flag==true) {

g.drawString("NAME::"+str6,500,500); g.drawString("CONTACT INFO::"+str7,500,520); g.drawString("TRAIN NAME::"+str1,500,540); g.drawString("SOURCE::"+str3,500,560); g.drawString("DESTINATION::"+str4,500,580); g.drawString("NUMBER OF SEATS::"+str5,500,600); g.drawString("DATE::"+str2,500,620); }

else g.drawString("CHECK AVAILABILITY!!!!!!",500,520);

} if(option==3)

{ if(flag==true) { option2=true; option1=true; g.drawString("SEATS ARE AVAILABLE",500,500); } else { flag=false; g.drawString("SORRY!!! SEATS ARE NOT AVAILABLE",500,500); } }}public void textValueChanged(TextEvent e){

if(e.getSource()==tf5)

26

Page 27: RAILWAY RESERVATION.doc

{ str5=tf5.getText(); i=Integer.parseInt(str5); } if(e.getSource()==tf2) {

str2=tf2.getText(); } if(e.getSource()==tf6) {

str6=tf6.getText(); } if(e.getSource()==tf7) { str7=tf7.getText(); } if(e.getSource()==tf9) { s1=tf9.getText(); ftime=Float.parseFloat(s1); System.out.println("from time by user"+ftime); } if(e.getSource()==tf10) { s2=tf10.getText(); ttime=Float.parseFloat(s2); System.out.println("to time by user"+ttime); }

}public void actionPerformed(ActionEvent e){

if(e.getSource()==b2) { option=2; } if(e.getSource()==b3) { option=3; url="jdbc:odbc:student"; Statement stmt=null;

27

Page 28: RAILWAY RESERVATION.doc

Connection con=null; try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(java.lang.ClassNotFoundException le) {

System.err.print("ClassNotFoundException: ");System.err.println(le.getMessage());

} try {

con = DriverManager.getConnection(url,"scott", "tiger");System.out.println("After connection");

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage()); }

try {

ResultSet rs=null; flag=false;

stmt = con.createStatement();if(i>0){ if (stmt.execute("select * from trainreservation1 where

noofseats>0")) { rs = stmt.getResultSet(); } else { System.err.println("select failed"); } } System.out.println("::"+stmt);

while (rs.next()) {

28

Page 29: RAILWAY RESERVATION.doc

String s5=rs.getString(1); s3=rs.getString(5); time1=Float.parseFloat(s3);

s4=rs.getString(6); time2=Float.parseFloat(s4); System.out.println("time::"+time1); System.out.println("time::"+time2); seats= rs.getInt(4);

if((seats>=i)&&(ftime<time1)&&(ttime>time1)&&(str1.equals(s5))) { flag=true; break; } } stmt.close();

con.close(); } catch(SQLException ex) {

System.err.println("SQLException1: " + ex.getMessage()); }}if(e.getSource()==b1){ option=1; url="jdbc:odbc:student";

Statement stmt=null; Connection con=null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

} catch(java.lang.ClassNotFoundException le) {

System.err.print("ClassNotFoundException: "); System.err.println(le.getMessage());}

try {

29

Page 30: RAILWAY RESERVATION.doc

con = DriverManager.getConnection(url,"scott", "tiger"); System.out.println("After connection");}

catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage());

} try {

ResultSet rs=null; stmt = con.createStatement(); if(i>0) {

if (stmt.execute("select * from trainreservation1 where noofseats>0"))

{ rs = stmt.getResultSet(); }

else {

System.err.println("select failed"); }

} String entry;

System.out.println("::"+stmt); while (rs.next()) { flag=false; nme = rs.getString(1); src = rs.getString(2); dest = rs.getString(3);

seats= rs.getInt(4); if(seats>=i) { if((ftime<time1)&&(ttime>time1)) { System.out.println(":"+src); System.out.println(":"+dest); System.out.println(":"+nme); if((nme.equals(str1))&&(src.equals(str3))&&(dest.equals(str4)))

30

Page 31: RAILWAY RESERVATION.doc

{ int k; k=seats-i; stmt.executeUpdate("update trainreservation1 set noofseats='"+k+"' where tname='"+str1+"'"); System.out.println("Successfully updated"); stmt.execute("insert into passenger1 values('"+str6+"','"+str1+"','"+str5+"','"+str2+"')"); flag=true; break; } } else System.out.println("No trains in that time\n");

} if(!flag) System.out.println("not successful");

} stmt.close();

con.close(); } catch(SQLException ex) {

System.err.println("SQLException1: " + ex.getMessage());}

} repaint();}}

31

Page 32: RAILWAY RESERVATION.doc

TESTING

 The testing phase is an important part of software development. It is the

process of finding errors and missing operations and also a complete

verification to determine whether the objectives are met and the user

requirements are satisfied. Software testing is carried out in three steps:

The first includes unit testing, where in each module is tested to

provide its correctness, validity and also determine any missing operations

and to verify whether the objectives have been met. Errors are noted down

and corrected immediately. Unit testing is the important and major part of

the project. So errors are rectified easily in particular module and program

clarity is increased. In this project entire system is divided into several

modules and is developed individually.  So unit testing is conducted to

individual modules.

       The second step includes Integration testing. It need not be the case, the

software whose modules when run individually and showing perfect results,

will also show perfect results when run as a whole. The individual modules

are clipped under this major module and tested again and verified the results.

This is due to poor interfacing, which may results in data being lost across

an interface. A module can have inadvertent, adverse effect on any other or

on the global data structures, causing serious problems.

The final step involves validation and testing which determines which

the software functions as the user expected. Here also some modifications

were. In the completion of the project it is satisfied fully by the end user.

32

Page 33: RAILWAY RESERVATION.doc

RESULTS:

ScreenShots:

1. Home page :

2.Train Details:

33

Page 34: RAILWAY RESERVATION.doc

34

Page 35: RAILWAY RESERVATION.doc

3.Check the availability of seats:

35

Page 36: RAILWAY RESERVATION.doc

4.After booking the ticket:

36

Page 37: RAILWAY RESERVATION.doc

5.PRINTING TICKET:

37

Page 38: RAILWAY RESERVATION.doc

6.Seats not available:

38

Page 39: RAILWAY RESERVATION.doc

7.Testcase_1 ScreenShot:

39

Page 40: RAILWAY RESERVATION.doc

8:Testcase_2 ScreenShot:

40

Page 41: RAILWAY RESERVATION.doc

9.Screen shot for seats are not available:

41

Page 42: RAILWAY RESERVATION.doc

CONCLUSION

In the last we conclude that MMTs Railways is having a strong IT

Infrastructure and a well equipped railway reservation system but there is

some shortcoming in the system on which we have tried to work on it and

successfully completed our project.

42

Page 43: RAILWAY RESERVATION.doc

FUTURE SCOPE

If anyone wants this project then he or she can make an additional database of TRAINFARE. And database for update availability of seats which is available after the cancellation of ticket on that specific train . etc.

He or she can also add some command buttons in the existing software and extend working of the software.

43