Programming Exercise IV: My Bus Itinerary: Part IV
(Industry-Level, Second-to-None Comprehensive Specifications)


Absolutely no copying others’ works

Development Requirements
When start developing the exercise, follow the requirements below:
The lists of bus stops and routes can NOT be saved in or loaded into Java data structures like arrays, ArrayList, LinkedList, HashMap, LinkedHashMap, HashSet, LinkedHashSet, TreeMap, TreeSet, PriorityQueue, Set, Vector, etc. though temporary results or data are allowed to be stored in Java data structures. This requirement will be carefully examined when grading.

Due Date and Submission Methods
Due on or before Wednesday, December 08, 2021 in class:

Objectives
There are more than 200 Java packages available and each one is huge. This course is not even able to cover few of them. This exercise tries to pick a useful one and has students be familiar with how packages work, so when students start working for the industry, they will have an idea of how to pick a Java package and use it to facilitate their works. Almost all business applications require to use databases, so it is very reasonable that the instructor picks the Java Database Connectivity (JDBC) for a detailed study. The JDBC APIs provide data access and management for databases from the Java programming language. This exercise is made as simple as possible. The most difficult part may be to be familiar with the APIs and set up the environment. Once one SQL command in a JDBC program works, the rest would be similar and routine. Keep in mind that the only effective way to learn a programming language is practicing, instead of studying concepts or writing some testing programs.
No pain, no gain 😂


Requirements
The requirements have to be followed precisely even though the developers may not agree with them. This application tries to implement a simple electronic-commerce system using a database. The application includes the following requirements:

A User Interface
An example of the exercise’s interface is shown below:


Database Design and Implementation
Based on the previous descriptions, database design is supplied by the instructor as follows. The following three tables show sample values of a relational bus itinerary database, of which rid, rsid, and sid are the primary keys of the tables route (or r), route_stop (or rs), and stop (or s), respectively. The begin and end are the foreign keys of the table route, and rid and sid are the foreign keys of the table route_stop. The ord is the sequence order number of the bus stop in the route starting from 0.


Database implementation on the instructor machine is shown as follows. The input data is for test only. The users are not supposed to know the IDs.

An Example of Oracle 12c Database Implementation

undcemcs02> source ~/.profile 

undcemcs02> sqlplus C##user.id/password@//65.52.222.73:1521/cdb1 

SQL*Plus: Release 12.2.0.1.0 Production on Sat Jul 17 03:32:43 2021
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Last Successful login time: Mon Jul 12 2021 02:31:52 -05:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> DROP SEQUENCE  route_seq; 

Sequence dropped.

SQL> CREATE SEQUENCE  route_seq  START WITH 1 INCREMENT BY 1 CACHE 100; 

Sequence created.

SQL> DROP TABLE  route; 

Table dropped.

SQL> CREATE TABLE  route ( 
  2    rid    INTEGER PRIMARY KEY, 
  3    begin  INTEGER NOT NULL, 
  4    end    INTEGER NOT NULL ); 

Table created.

SQL> DROP SEQUENCE  stop_seq; 

Sequence dropped.

SQL> CREATE SEQUENCE  stop_seq  START WITH 1 INCREMENT BY 1 CACHE 100; 

Sequence created.

SQL> DROP TABLE  stop; 

Table dropped.

SQL> CREATE TABLE  stop ( 
  2    sid   INTEGER PRIMARY KEY, 
  3    name  VARCHAR(32) NOT NULL ); 

Table created.

SQL> DROP SEQUENCE  route_stop_seq; 

Sequence dropped.

SQL> CREATE SEQUENCE  route_stop_seq  START WITH 1 INCREMENT BY 1 CACHE 100; 

Sequence created.

SQL> DROP TABLE  route_stop; 

Table dropped.

SQL> CREATE TABLE  route_stop ( 
  2    rsid  INTEGER PRIMARY KEY, 
  3    rid   INTEGER NOT NULL, 
  4    sid   INTEGER NOT NULL, 
  5    ord   INTEGER NOT NULL ); 

Table created.

SQL> INSERT INTO  stop 
  2    SELECT  stop_seq.NEXTVAL, 'Alerus Center'  FROM DUAL; 

1 row created.

SQL> INSERT INTO  stop 
  2    SELECT  stop_seq.NEXTVAL, 'Starbucks'  FROM DUAL; 

1 row created.

SQL> INSERT INTO  route 
  2    SELECT  route_seq.NEXTVAL, 1, 2  FROM DUAL; 

1 row created.

SQL> INSERT INTO  route_stop 
  2    SELECT  route_stop_seq.NEXTVAL, 1, 1, 0 FROM DUAL; 

1 row created.

SQL> INSERT INTO  route_stop 
  2    SELECT  route_stop_seq.NEXTVAL, 1, 2, 8 FROM DUAL; 

1 row created.

SQL> SELECT * FROM  stop; 

SID            NAME  
---    ------------------- 
  1    Alerus Center           
  2    Starbucks

SQL> SELECT * FROM  route; 

RID    BEGIN    END
---    -----    ---
  1      1       2

SQL> SELECT * FROM  route_stop; 

RSID    RID    SID    ORDER
----    ---    ---    -----
 1       1      1       0
 2       1      2       5

SQL> commit; 
SQL> exit; 
Disconnected from Oracle Database 12c Enterprise Edition Release
 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application
 Testing options

undcemcs02>

The italic text with a white color and a navy background color is entered by users.



Programming Hints
The algorithm and SQL commands below are for your reference. They may or may not be used in this exercise. The following steps may be used to find the shortest itinerary (the one with the lowest number of bus stops):


  Find-Shortest-Itinerary( start, final )

  1. Each itinerary (from the start stop to the final stop) may use either (i) 1 route or (ii) 2 routes and one transfer.
  2. Find all possible routes and transfers for the itinerary by embedding the SQL command in JDBC (interface) such as
             Route One   Route Two   Transfer ID    Transfer Name
           ----------- ----------- ------------- ----------------
                   100         200            35   Altru Hospital
                   100         200            40              UND
                   100         300            60          Menards
                   100         300            75    Columbia Mall
  3. Save the above results in the data structures of JDBC.
  4. List the bus stops of each possible itinerary by embedding two of the SQL command in JDBC (interface) such as
                           NAME      ORD      ROUTE
             ------------------   ------   --------
               Aerospace School        4        100
                    Burger King        3        100
                            UND        2        100
                 Altru Hospital        1        100
    
                           NAME      ORD      ROUTE
             ------------------   ------   --------
                 Altru Hospital        0        200
                        Walmart        1        200
                  Alerus Center        2        200
                      Starbucks        3        200
  5. Drop the itinerary with duplicate stops from consideration.
  6. The number of bus stops between the start stop and the final stop is

    1 route: #_stops(start, final) or
    2 routes: #_stops(start, final) = #_stops(start, transfer) + #_stops(transfer, final) – 1

  7. For each row of the result of Step 2, find the number of bus stops between two stops by embedding the SQL command in JDBC (interface) such as
                 ROUTE           STOP 1          STOP 2       NUMBER
             ---------    -------------    ------------    ---------
                   200          Walmart             UND            4
  8. Display the shortest itinerary by embedding two of the SQL command in JDBC (interface) such as
                           NAME      ORD      ROUTE
             ------------------   ------   --------
               Aerospace School        4        100
                    Burger King        3        100
                            UND        2        100
                 Altru Hospital        1        100
    
                           NAME      ORD      ROUTE
             ------------------   ------   --------
                 Altru Hospital        0        200
                        Walmart        1        200
                  Alerus Center        2        200
                      Starbucks        3        200

The following SQL commands may be used in this exercise.

The above SQL commands may be needed for finding the shortest itinerary, and the extras below are the SQL commands used by the instructor for the other functions. You can hide them, so they will not distract your attention from solving the problem.

     

Evaluations
The following features will be considered when grading: