Вы находитесь на странице: 1из 4

Assignment #2

Description:

Your task is to design a scheduler for the Sheridan Rail Corporation which keeps track of all daily
scheduled trips for the railway. Users can add new trips as well as perform searches (queries) on the
scheduler based on departing city. The focus of this assignment is on JDBC, dynamic SQL using prepared
statements, and object-relational mappings.

This assignment is to be completed individually you have been warned!

Your submission must consist of a zip file containing your entire Eclipse project. You will NOT receive
any program completeness marks if you only submit your .java files!

Specifications:

Database
You are provided with a database script, sheridanrail.sql that does the following:
Create a new database schema called SheridanRail
Create a new table called Route that contains the following fields:
o RouteNumber A unique number identifying a train route, primary key
o Departing The departing city of a route
o Destination The final destination of a route
o Capacity maximum number of passengers allowed on this route
Inserts a series of records corresponding to existing routes

Your Program
You are required to implement the following classes:
a) DBConnectionFactory.java A class that manages connections to your database and associated
resources. You can use the DBConnectionFactory.java from your homework, but you must use
get connections to the database and close all JDBC objects with it.
b) Route.java A class that models the Route table from the SheridanRail database. This class
provides an object-relational mapping with the Route table.
c) SheridanRail.java A class with a main method which repeatedly prompts the user to enter one
of the following options (use a loop!):
o 1 List all routes by departing city
o 2 Add a new route
o 0 Exit the program
Implement the following static method signatures:
o getRoutesByDepartingCity(String departing) - Returns an ArrayList of Route objects
consisting of all routes that have a departing city matching the one supplied by the
user. Hint: you may want to create a global static ArrayList to store all possible
Route instances, and create a second local ArrayList inside this method to return
only the relevant data. Retrieve the relevant data from the database and create an
ArrayList by iterating through the ResultSet, but remember to make the database do
the work wherever possible! Be sure the returned ArrayList from this method
contains only route instances where the departing city matches.
o addRoute(Route route) Adds a new record to the route SQL table using a
PreparedStatement and a duplicate route to your ArrayList of Route objects. This
method should return true if the new SQL record was added successfully, false
otherwise.
Perform the following based on the option selected:
o If the user enters 1:
Prompt the user to type in the departing city
Call the static getRoutesByDepartingCity method that returns an ArrayList
of routes
Display the information on the relevant routes returned
o If the user enters 2:
Prompt the user to enter the route #, departing city, destination, and
capacity of the new route
Call the static addRoute method which will add the information to the
database using a PreparedStatement and add a matching Route instance to
your ArrayList
Display a message stating whether the new route was successfully added to
the database and ArrayList or not based on the value returned by addRoute
o If the user enters 0:
Display a message stating that the program is exiting
o If the user enters any other value:
Display a message stating that the entry is invalid

Files for Submission

Please zip your entire Eclipse project directory and attach the zip to the SLATE2 Dropbox.
Other Requirements:

In order for your application to be fully correct, the following requirements must be satisfied:
Your program must handle SQL Exceptions by displaying the error message, SQL state, and error
code.
Your program should not terminate without providing some information to the user, even if the
user provided invalid input.
When adding a route, a message needs to be sent to the user informing him/her that the
addition was successful or not.
Your application should be as secure as possible: Use prepared statements for all queries

Sample Output:

The following is a template of sample console input and output for your SheridanRail program. The text
in red is input entered by the user:

Sher i dan Rai l Ser vi ces
1 - Li st al l r out es by depar t i ng ci t y
2 - Add a new r out es
0 - Exi t
Ent er an opt i on: 2
Ent er i ng Rout e I nf or mat i on. . .
Ent er Rout e #: 1234
Ent er Depar t i ng Ci t y: Halifax
Ent er Dest i nat i on: Quebec City
Capaci t y of r out e: 123
New r out e added successf ul l y

Sher i dan Rai l Ser vi ces
1 - Li st al l r out es by depar t i ng ci t y
2 - Add a new r out e
0 - Exi t
Ent er an opt i on: 1
Li st i ng al l r out e by depar t i ng ci t y. . .
Ent er depar t i ng ci t y: Halifax

Tr i ps l eavi ng Hal i f ax:
Rout e #: 766
Depar t i ng: Hal i f ax
Dest i nat i on: Mont r eal
Capaci t y: 139

Rout e #: 844
Depar t i ng: Hal i f ax
Dest i nat i on: Quebec Ci t y
Capaci t y: 132


Sher i dan Rai l Ser vi ces
1 - Li st al l r out es by depar t i ng ci t y
2 - Add a new r out e
0 - Exi t
Ent er an opt i on: 0
Exi t i ng pr ogr am. . .


Submission:

The template for your classes should be as follows:

/ * Name: [ Your Name]
Assi gnment : Assi gnment 2

Descr i pt i on: [ A br i ef descr i pt i on of cl assName]
*/
publ i c cl ass Cl assName {
/ / Your code her e
}

You will be submitting a zip of your entire Eclipse project.

Remember that your submission date/time is based on SLATE2. You can hand it in early, and even hand
it in again if you need to, but there is no such thing as late. The clock at Sheridan is always right! Please
do not email me late submissions. Get it done with a day or two to spare.

Evaluation:
This assignment is out of a total of 30 marks with the following breakdown:

DBConnectionFactory.java

Loads driver and gets a DB connection via getConnection() method

Methods that close all resources associated with the database
/2


Route.java

Object-relational mapping

Implementation of getRoutesByDepartingCity method

Implementation of addRoute method
/12


PROGRAM COMPLETENESS (SheridanRail.java)

Program compiles, runs and follows specifications defined in assignment document
/12
Proper coding conventions (readability, naming conventions, etc.)
/4



TOTAL

/30

Вам также может понравиться