A Report On Motorway Toll Booths Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

This assignment is about simulation for determining the number of tollbooths that might be required at any particular motorway exit point. It is hoped that results from running the simulation would

1. Determine the maximum number of tollbooths to be built at particular exit points

2. Determine the number of these booths that need to be opened, depending on the traffic conditions, at a particular time.

This simulation determines how many tollbooths need to be opened or built with a graphical display. The queues of traffic at each booth are dynamic in that vehicles appear at the tails and move off at the heads once the toll has been paid. The number of tollbooths required is determined by the throughput of vehicles in a certain time.

This simulation allows the user to set the values of average no of car passing in particular time interval, predefined throughput time, and average toll payment time to start simulation and calculate the number of tollbooth required by the particular exit point. The simulation also provides a means to store the result of scenario for future reference and analysis.

Task 1

Introduction

Task 1 is about

a. The design of a tollbooth and a vehicle classes

b. The implementation of a tollbooth and a vehicle classes

c. Testing of the tollbooth and vehicle classes

1.1 The design of a tollbooth and a vehicle classes

Symbol

Control type

Control Name

Description

JLabel

jlbltollpaymenttime

Show the average toll payment time for one car.

JLabel

jlblTollbooth

Show the image of tollbooth.

Jtextbox

jtxtThroughputTime

Show throughput time of the last leaving car.

Jpanel

jpHighway

Act as the highway for car to move through.

Jpanel

jpGate

Act as the tollbooth gate.

Jlabel

jCarImage

Show image of the car.

Jlabel

jlblThroughputTime

Count throughput time for a car to pass through the gate.

1.2 Pseudo code

1.2.1 Pseudo code for Tollbooth class

USE VARIABLES:

tollpaymenttime and locationy as type Integer

moving of type Boolean

alvehicle of type ArrayList

jpHighway, jpGate of type JPanel

jlbltollpaymenttime of type JLabel

jtxtThroughputTime of type JTextbox

Procedure createVehicle

Begin

Assign locationy value 110+(alvehicle.size()*90)

Create a vehicle with parameter passing locationy and this class

Add the created car to the alvehicle (ArrayList)

Adjust the location and size of the created vehicle

Add the created car to the jpHighway

End

End Procedure

Procedure removeVehicle

Begin

IF there is at least one car or more in the alvehicle ArrayList Then

Set invisible to the first index car object from the alvehicle ArrayList

Remove the first index car object from the alvehicle ArrayList

End IF

End

End Procedure

Procedure tollpayment

Begin

Create a thread

WHILE (true)

IF there is at least one car or more in the alvehicle ArrayList Then

FOR (int i=0; i>= tollpaymenttime; i++)

Set i to the jlbltollpaymenttime

Stop the program progress for one second using thread

End FOR

Set visible of the jpGate to false

Assign moving to true

Set the throughput time of the car to jtxtThroughputTime

Stop the program progress for 7 second to await car for pass through

the gate by using thread

Set visible of the jpGate to true

Call procedure removeVehicle

End IF

End

End Procedure

Function getThroughputTime of Type Integer

Begin

Convert the value of jtxtThroughputTime to integer and then return the converted

Value

End

End Function

1.2.2 Pseudo code for Vehicle Class

User Variables: locationy, i of Type Integer

tb of Type Integer

Function getThroughputTime of Type Integer

Begin

Convert the value of jtxtThroughputTime to integer and then return the converted

Value

End

End Function

Procedure runThroughPutTime

Begin

Create a thread

WHILE (true)

Assign 0 to i

Set the value i to jlblThroughputTime

Stop the program progress for one second by using thread

Increment i by 1

NEXT

End

End Procedure

Procedure moveVehicle

Begin

Create a thread

WHILE (true)

IF tb.moving is true then

FOR int i=0; i<90; i++

Move vehicle to gate by one unit

Stop program progress for 0.05 seconds

End For

Assign tb.moving to false

End IF

NEXT

End

End Procedure

1.3 Implementation of the tollbooth and vehicle classes

1.3.1 TollBooth Class

Variables

private int tollpaymenttime;

protected ArrayList alvehicle=new ArrayList();

private int locationy=0;

protected boolean moving=false;

Methods

// Creates new form TollBooth

public TollBooth(int tollpaymenttime) {

initComponents();

alvehicle.clear();

this.tollpaymenttime=tollpaymenttime;

tollpayment();

}

//Create a vehicle, add the vehicle to alvehicle arraylist and then add it to jpHighway panel.

protected void createVehicle(){

locationy=110+(alvehicle.size()*90);

Vehicle v=new Vehicle(locationy, this);

alvehicle.add(v);

v.setBounds(15,locationy,40,70);

jpHighway.add(v);

}

//Set invisible to the first index car from the alvehicle arraylist and remove the vehicle from the alvehicle arraylist

protected void removeVehicle(){

if(!alvehicle.isEmpty()){

((Vehicle)alvehicle.get(0)).setVisible(false);

alvehicle.remove(0);

}

}

//Run toll payment time, set invisible to jpGate and then allow vehicle to pass through the gate.

protected void tollpayment(){

Thread t=new Thread(new Runnable() {

public void run() {

while(true){

if(!alvehicle.isEmpty()){

for(int i=tollpaymenttime;i>=0;i--){

jlbltollpaymenttime.setText("Payment time= "+i);

try{

Thread.sleep(1000);

}catch(InterruptedException e){

}

}

jpGate.setVisible(false);

moving=true;

jtxtThroughputTime.setText(((Vehicle)alvehicle.get(0)).getThroughputTime());

try{

Thread.sleep(7000);

}catch(InterruptedException e){

}

jpGate.setVisible(true);

removeVehicle();

moving=false;

}

}

}

});

t.start();

}

//Convert the string value of jtxtThroughputTime to Integer and return the converted value.

protected int getThroughputTime(){

return Integer.parseInt(jtxtThroughputTime.getText().trim());

}

1.3.2 Vehicle Class

Variables

private int locationy;

private TollBooth tb;

Methods

//Create a vehicle object.

public Vehicle(int locationy,TollBooth tb) {

initComponents();

this.locationy=locationy;

this.tb=tb;

moveVehicle();

runThroughPutTime();

}

//Return the string value of jlblThroughputTime label.

protected String getThroughputTime(){

return jlblThroughputTime.getText().trim();

}

//Run throughput time for one car

private void runThroughPutTime(){

Thread t=new Thread(new Runnable() {

public void run() {

int i=0;

while(true){

jlblThroughputTime.setText(i+" ");

try{

Thread.sleep(1000);

}catch(InterruptedException e){

}

i++;

}

}

});

t.start();

}

//Allow to move car by 90 units toward tollgate when tb.moving is true.

private void moveVehicle(){

Thread t=new Thread(new Runnable() {

public void run() {

while(true){

if(tb.moving){

for(int i=0;i<90;i++){

setLocation(15, locationy-=1);

try{

Thread.sleep(50);

}

catch(InterruptedException e){

}

}

tb.moving=false;

}

}

}

});

t.start();

}

1.4 Testing of the tollbooth and vehicle classes

Test data: payment time=5 seconds

Test description: When a car arrives at the toll gate, it stops for a particular time period for toll payment. After it has paid the payment, the gate is opened and it moves through the toll gate.

Task 2

Design of the user interface form Highway and Simulation form

Task 2.1 .1 Highway user input design

Symbol

Control type

Control name

Description

JTextbox

jtxtHID

Display the auto-generated Highway ID.

Jtextbox

jtxtHNo

Accept the user's input value (Highway no)

Jtextbox

jtxtEPN

Accept the user's input value (exit point name)

Jlistbox

jlstShowHighways

Display Highway no from the database and show the full data on the respective textboxes.

JmenuItem

jmnuSave

Validate the value from textboxes and store validated data into the database.

JmenuItem

jmnuDelete

Delete the data from the database, based on the selected value from the listbox.

JmenuItem

jmnuCancel

Clear all the data on textboxes.

Task 2.1.2 Pseudo code for the Highway user interface

Use variables: alHID, alHNo, alEPN of Type ArrayList

hID of Type String

jlstShowHighways of Type JListbox

check of Type Boolean

Function newHighwayID : Of type String

Begin

Assign H-00001 to hID

Make a connection to the database

Get the Max Highway ID from the database by making SQL query and set the

Value to hID

Calculate new Highway ID from the value of hID and assign the calculated value

To the hID

Return hID

End

End Function

Procedure fillHighway

Begin

Make a connection to the database named TollboothSimulation

Get all highway Ids, highway nos and exit point names from the database and

insert them into alHID, alHNo and alEPN

Fill the jlstShowHighways listbox with values from alHNo

Close the connection

End

End Procedure

Function data_Validation : OF type Boolean

Begin

Assign true to check

IF there is no user's input value in the jtxtHNo textbox then

Warn the user to enter the value

Assign false to check

Else IF there are more than 30 characters in the jtxtHNo textbox then

Warn the user to reenter the value less than 30 charcters

Assign false to check

Else IF there is no user's input value in the jtxtEPN textbox then

Warn the user to enter the value

Assign false to check

Else IF there are more than 30 characters in the jtxtEPN textbox then

Warn the user to reenter the value less than 30 characters

Assign false to check

End IF

Return check

End

End Function

Procedure save_Data

Begin

Make a connection to the database named TollboothSimulation

Insert into database's Highway table values from jtxtHID, jtxtHNo and jtxtEPN by

making SQL query

Close the connection

End

End Procedure

Procedure remove_Data

Begin

Make a connection to the database named TollboothSimulation

Delete the user's selected record from the database table named Highway

Close the connection

End

End Procedure

2.2.1 Simulation user input design

Symbol

Control type

Control name

Description

JTextField

jtxtSID

Display the auto generated simulation ID.

JCombobox

jcboHighwayNo

List the highway no retrieved from the database table named Highway and allow users to select one highway no.

JCombobox

jcboDay, jcboMonth, jcboYear

List the available date, month and year and allow users to select one.

JCombobox

jcboHour

jcboMinute

jcboSecond

List the available hour, minute and second and allow users to select one.

JTextfield

jtxtNoofCar

Allow users to input no of cars.

JTextfield

jtxtDuration

Allow users to input duration.

JTextfield

jtxtThroughputTime

Allow users to input predefined throughput time.

JTextfield

jtxtAverageTimepayment

Allow users to input average toll payment time for one car.

JTextfield

jtxtNooftollbooth

Display the result of total no of booths to be built which is attained from simulation.

JMenuItem

jmnuSave

Save the simulated value and user's input into the database table named Simulation.

2.2.2 Pseudo code for Simulation user input form

Use variables: preDeterminedThroughputTime, averagePaymentTime,

averageNoOfCar OF type Integer

alHID and alHNo of type ArrayList

simulationDate, simulationTime, simulationID of Type String

noOfCar, duration of type Integer

jtxtNoofCar, jtxtDuration of type JTextfield

Procedure save_Data

Begin

Make a connection to the database named TollboothSimulation

Insert into database's Simulation table values from alHID's selected ID, jtxtSID,

simulationDate, simulationTime, jtxtnoOFCar's value, jtxtduration's value

jtxtthroughputTime's value, jtxtAveragPaymentTime's value and

jtxtnoofTollbooth's value by making SQL query

Close the connection

End

End Procedure

Function newSimulationID : Of type String

Begin

Assign S-0000001 to simulationID

Make a connection to the database

Get the Max Simulation ID from the database's table named Simulation by

making SQL query and set the Value to simulationID

Calculate new Simulation ID from the value of simulationID and assign the

calculated value to simulationID

Return simulationID

End

End Function

Procedure fillHighway

Begin

Make a connection to the database named TollboothSimulation

Get all highway Ids, highway nos and exit point names from the database ‘s table

named Highway and insert them into alHID, alHNo

Fill the jcboHighwayNo with values from alHNo

Close the connection

End

End Procedure

Function data_Validation : OF type Boolean

Begin

Assign false to check

IF there is no user's input value in the jtxtNoofCar textbox then

Warn the user to enter the value

Else IF there is no user's input value in the jtxtDuration textbox then

Warn the user to enter the value

Else IF there is no user's input value in the jtxtThroughputTime then

Warn the user to enter the value

Else IF there is no user's input value in the jtxtAverageTimepayment then

Warn the user to enter the value

Else

IF value in the jtxtNoofCar cannot be converted to Integer then

Warn the user to reenter numeric value

Else

Assign true to check

End IF

IF value in the jtxtDuration cannot be converted to Integer then

Warn the user to reenter numeric value

Else

Assign true to check

End IF

IF value in the jtxtThroughputTime cannot be converted to Integer then

Warn the user to reenter numeric value

Else

Assign true to check

End IF

IF value in the jtxtAverageTimePayment cannot be converted to Integer

Warn the user to reenter numeric value

Else

Assign true to check

End IF

End IF

Return check

End

End Function

Function calculateAverageCarPassing : Of type Integer

Begin

Convert the String value from the jtxtNoofCar to Integer and assign the converted

value to noOfCar variable

Convert the String value from the jtxtDuration to Integer and assign the converted

value to duration variable

averageNoOfCar= noOfCar /duration

Return averageNoOfCar

End

End Function

Task 3

Implementation and Testing the designs implemented in Task 2

3.1.1 Implementation of Highway user input form

Class Highway

Variables

private ArrayList alHID=new ArrayList();

private ArrayList alHNo=new ArrayList();

private ArrayList alEPN=new ArrayList();

Methods

/** Creates new form Highway */

public Highway() {

initComponents();

jtxtHID.setText(newHighWayID());

fillHighway();

jtxtHNo.requestFocus();

}

//Produce new Highway ID.

private String newHighWayID(){

String hID="H-00001";

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("Select Max(HighWayID) From Highway");

if(rs.next()){

hID=rs.getString(1);

int id=Integer.parseInt(hID.substring(2))+1;

if(id<10) hID="H-0000"+id;

else if(id<100) hID="H-000"+id;

else if(id<1000) hID="H-00"+id;

else if(id<10000) hID="H-0"+id;

else hID="H-"+id;

}

rs.close();

st.close();

con.close();

}

catch(Exception e){

e.printStackTrace();

}

return hID;

}

//Fill the alHID, alHNo and alEPN with data from the database

protected void fillHighway(){

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("Select * from Highway Order by HighwayNo ASC");

alHID.clear();

alHNo.clear();

alEPN.clear();

jlstShowHighways.setListData(alHNo.toArray());

while(rs.next()){

alHID.add(rs.getString(1));

alHNo.add(rs.getString(2));

alEPN.add(rs.getString(3));

}

jlstShowHighways.setListData(alHNo.toArray());

rs.close();

st.close();

con.close();

}

catch(Exception e){

e.printStackTrace();

}

}

//Validate the user's input data and return true if the user's input data is valid.

private boolean data_Validation(){

boolean check=true;

if(jtxtHNo.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter Highway no");

jtxtHNo.requestFocus();

check=false;

}

else if(jtxtHNo.getText().trim().length()>30){

JOptionPane.showMessageDialog(this, "More than 30 characters");

jtxtHNo.selectAll();

jtxtHNo.requestFocus();

check=false;

}

else if(jtxtEPN.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter Exit Point Name");

jtxtEPN.requestFocus();

check=false;

}

else if(jtxtEPN.getText().trim().length()>30){

JOptionPane.showMessageDialog(this, "More than 30 characters");

jtxtEPN.selectAll();

jtxtEPN.requestFocus();

check=false;

}

return check;

}

//Save the user's input data to the database

private void save_Data(){

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

String id=jtxtHID.getText();

String hno=jtxtHNo.getText().trim();

String epn=jtxtEPN.getText().trim();

if(jmnuSave.getText().contentEquals("Save")){

st.execute("INSERT INTO Highway VALUES('"+id+"','"+hno+"','"+epn+"')");

}

else{

st.execute("UPDATE Highway Set HighwayNo='"+hno+"',ExitPointName='"+epn+"' Where HighwayID='"+id+"'");

}

st.close();

con.close();

fillHighway();

cancel_Data();

}

catch(Exception e)

{

e.printStackTrace();

}

}

//Delete the selected data from the database.

private void remove_Data(){

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

st.executeUpdate("Delete from Highway where HighwayID='"+alHID.get(jlstShowHighways.getSelectedIndex()).toString()+"'");

st.close();

con.close();

fillHighway();

}

catch(Exception e){

e.printStackTrace();

}

}

//clear data.

private void cancel_Data(){

jtxtHNo.setText("");

jtxtEPN.setText("");

jtxtHID.setText(newHighWayID());

jmnuSave.setText("Save");

jtxtHNo.requestFocus();

}

//Ask confirmation from the user whether he wants to exit or not.

private void exit(){

int option=JOptionPane.showConfirmDialog(this, "Are you sure to exit?","Exit",JOptionPane.YES_NO_OPTION);

if(option==JOptionPane.YES_OPTION){

dispose();

}

else

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

}

private void jlstShowHighwaysValueChanged(javax.swing.event.ListSelectionEvent evt) {

if(jlstShowHighways.getSelectedIndex()!=-1){

jmnuSave.setText("Update");

jtxtHID.setText(alHID.get(jlstShowHighways.getSelectedIndex()).toString());

jtxtHNo.setText(alHNo.get(jlstShowHighways.getSelectedIndex()).toString());

jtxtEPN.setText(alEPN.get(jlstShowHighways.getSelectedIndex()).toString());

}

}

private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {

exit();

}

private void jmnuSaveActionPerformed(java.awt.event.ActionEvent evt) {

if(data_Validation()){

save_Data();

JOptionPane.showMessageDialog(this, "Data has been saved successfully.");

}

}

private void jmnuDeleteActionPerformed(java.awt.event.ActionEvent evt) {

if(jlstShowHighways.getSelectedIndex()!=-1){

int i=JOptionPane.showConfirmDialog(this, "Are you sure to delete?", "Delete", JOptionPane.YES_NO_OPTION);

if(i==JOptionPane.YES_OPTION){

remove_Data();

cancel_Data();

}

}

}

private void jmnuCancelActionPerformed(java.awt.event.ActionEvent evt) {

cancel_Data();

}

3.1.2 Testing of Highway user input form

3.1.2.1 Data insertion testing

Test data

Highway ID= H-00001

Highway No=YB-2

Exit point name= Bago

Expected result

Insert a record into the database table named Highway

Actual result

Fig 3.1.2.1.1, 3.1.2.1.2, 3.1.2.1.3, 3.1.2.1.4

Action

Click the save menu after data has been prepared.

3.1.2.2 Data validation testing

Test description: If users try to insert into the database table without data, the following result will occur (Fig 3.1.2.2.1, 3.1.2.2.2)

3.2.1 Implementation of Simulation user input form

Simulation class

Variables

public int preDeterminedThroughputTime, averagePaymentTime, averageNoOfCar;

private ArrayList alHID=new ArrayList();

private ArrayList alHNo=new ArrayList();

Methods

public class Simulation extends javax.swing.JInternalFrame {

public int preDeterminedThroughputTime, averagePaymentTime, averageNoOfCar;

private ArrayList alHID=new ArrayList();

private ArrayList alHNo=new ArrayList();

public Simulation() {

initComponents();

int endYear=2050;

for(int startYear=2000;startYear<=endYear;startYear++){

jcboYear.addItem(startYear);

}

fillTimeOftheDay();

int year=Integer.parseInt(jcboYear.getSelectedItem().toString());

int month=Integer.parseInt(jcboMonth.getSelectedItem().toString());

fillDay(year,month);

jtxtSID.setText(newSimulationID());

fillHighway();

}

//Fill jcboDay, jcboMonth, jcboYear with available date, month and year.

private void fillDay(int year,int month){

int endDay=0;

if(new GregorianCalendar().isLeapYear(year)&&month==2){

endDay=29;

}

else if(month==2){

endDay=28;

}

else if(month==4||month==6||month==9||month==11){

endDay=30;

}

else{

endDay=31;

}

jcboDay.removeAllItems();

for(int i=1;i<=endDay;i++){

jcboDay.addItem(i);

}

}

//save the simulated result and user's input value into database

private void save_Data(){

String simulationDate=jcboDay.getSelectedItem()+"/"+jcboMonth.getSelectedItem()+"/"+jcboYear.getSelectedItem();

String simulationTime=jcboHour.getSelectedItem()+":"+jcboMinute.getSelectedItem()+":"+jcboSecond.getSelectedItem()+""+jcboamorpm.getSelectedItem();

int noOfCars=Integer.parseInt(jtxtNoofCar.getText().trim());

int duration=Integer.parseInt(jtxtDuration.getText().trim());

int throughputTime=Integer.parseInt(jtxtThroughputtime.getText().trim());

int averageTimePayment=Integer.parseInt(jtxtAverageTimepayment.getText().trim());

int noOfBooths=Integer.parseInt(jtxtNooftollbooth.getText().trim());

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

st.execute("Insert into Simulation Values('"+alHID.get(jcboHighwayNo.getSelectedIndex())+"','"+jtxtSID.getText()+"','"+simulationDate+"','"+simulationTime+"',"+noOfCars+","+duration+","+throughputTime+","+averageTimePayment+","+noOfBooths+")");

//st.execute("Insert into SimulationDetails Values('"+simulationTime+"','"+jtxtSID.getText()+"','"+jtxtNoofCar.getText()+"','"+jtxtDuration.getText()+"','"+jtxtThroughputtime.getText()+"','"+jtxtAverageTimepayment.getText()+"','"+jtxtNooftollbooth.getText()+"')");

st.close();

con.close();

setToday();

jtxtSID.setText(newSimulationID());

}

catch(Exception e){

e.printStackTrace();

}

}

//Set the combox to the date of today.

private void setToday(){

GregorianCalendar gc=new GregorianCalendar();

jcboYear.setSelectedIndex(gc.get(gc.YEAR)-2009);

jcboMonth.setSelectedIndex(gc.get(gc.MONDAY));

jcboDay.setSelectedIndex(gc.get(gc.DAY_OF_MONTH));

}

//Produce new Simulation ID and return it.

private String newSimulationID(){

String simulationID="S-0000001";

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("Select Max(SimulationID) From Simulation");

if(rs.next()){

simulationID=rs.getString(1);

int id=Integer.parseInt(simulationID.substring(2))+1;

if(id<10)simulationID="S-000000"+id;

else if(id<100)simulationID="S-00000"+id;

else if(id<1000)simulationID="S-0000"+id;

else if(id<10000)simulationID="S-000"+id;

else if(id<100000)simulationID="S-00"+id;

else if(id<1000000)simulationID="S-0"+id;

else simulationID="S-"+id;

}

rs.close();

st.close();

con.close();

}

catch(Exception e){

e.printStackTrace();

}

return simulationID;

}

//Fill the jcboHighwayNo combox with available Highway no.

protected void fillHighway(){

try{

Connection con=Main_Form.databaseConnection();

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("Select HighwayID, HighwayNo from Highway Order by HighwayNo ASC");

alHID.clear();

alHNo.clear();

while(rs.next()){

alHID.add(rs.getString(1));

alHNo.add(rs.getString(2));

}

jcboHighwayNo.removeAllItems();

for(int i=0;i<alHNo.size();i++){

jcboHighwayNo.addItem(alHNo.get(i));

}

rs.close();

st.close();

con.close();

}

catch(Exception e){

e.printStackTrace();

}

}

//Fill jcboHour, jcboMinute and jcboSecond with available hour, minute and second.

private void fillTimeOftheDay(){

int hour=12;

int minute=60;

int second=60;

for(int i=1;i<=hour;i++){

jcboHour.addItem(i);

}

for(int i=1;i<=minute;i++){

jcboMinute.addItem(i);

}

for(int i=1;i<=second;i++){

jcboSecond.addItem(i);

}

jcboamorpm.addItem("am");

jcboamorpm.addItem("pm");

}

//Check the exit of this form.

private void exit(){

int option=JOptionPane.showConfirmDialog(this, "Are you sure to exit?","Exit",JOptionPane.YES_NO_OPTION);

if(option==JOptionPane.YES_OPTION)

dispose();

else

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

}

//Validate the user's input value and return true if the user correctly enter validated value.

public boolean data_Validation(){

boolean check=false;

if(jtxtNoofCar.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter no of car");

jtxtNoofCar.requestFocus();

}

else if(jtxtDuration.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter time intervals");

jtxtDuration.requestFocus();

}

else if(jtxtThroughputtime.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter throughput time");

jtxtThroughputtime.requestFocus();

}

else if(jtxtAverageTimepayment.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter average time payment");

jtxtAverageTimepayment.requestFocus();

}

else{

try{

Integer.parseInt(jtxtNoofCar.getText().trim());

check=true;

}

catch(Exception e){

JOptionPane.showMessageDialog(this, jtxtNoofCar.getText().trim()+" is not numeric.");

jtxtNoofCar.requestFocus();

check=false;

}

try{

Integer.parseInt(jtxtDuration.getText().trim());

check=true;

}

catch(Exception e){

JOptionPane.showMessageDialog(this, jtxtDuration.getText().trim()+" is not numeric.");

jtxtDuration.requestFocus();

check=false;

}

try{

Integer.parseInt(jtxtThroughputtime.getText().trim());

check=true;

}

catch(Exception e){

JOptionPane.showMessageDialog(this, jtxtThroughputtime.getText().trim()+" is not numeric.");

jtxtThroughputtime.requestFocus();

check=false;

}

try{

Integer.parseInt(jtxtAverageTimepayment.getText().trim());

check=true;

}

catch(Exception e){

JOptionPane.showMessageDialog(this, jtxtAverageTimepayment.getText().trim()+" is not numeric.");

jtxtAverageTimepayment.requestFocus();

check=false;

}

}

return check;

}

//Clear values of all controls.

private void clearData(){

jtxtNoofCar.setText("");

jtxtDuration.setText("");

jtxtThroughputtime.setText("");

jtxtAverageTimepayment.setText("");

jtxtNooftollbooth.setText("");

}

private boolean dataValidationForAverageCarPassing(){

boolean b=false;

if(jtxtNoofCar.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter no of cars.");

jtxtNoofCar.requestFocus();

}

else if(jtxtDuration.getText().trim().isEmpty()){

JOptionPane.showMessageDialog(this, "Enter time interval");

jtxtDuration.requestFocus();

}

else{

try{

Integer.parseInt(jtxtNoofCar.getText().trim());

}

catch(Exception e){

JOptionPane.showMessageDialog(this, jtxtNoofCar.getText().trim()+" is not numeric.");

}

try{

Integer.parseInt(jtxtDuration.getText().trim());

}

catch(Exception e){

JOptionPane.showMessageDialog(this, jtxtDuration.getText().trim()+" is not numeric.");

}

b=true;

}

return b;

}

//Calculate average car passing per minute and return the calculated value.

public int calculateAverageCarPassing(){

int noOfCar;

int timeInterval;

int averageCarPassing=0;

if(dataValidationForAverageCarPassing()){

noOfCar=Integer.parseInt(jtxtNoofCar.getText().trim());

timeInterval=Integer.parseInt(jtxtDuration.getText().trim());

try{

averageCarPassing=noOfCar/timeInterval;

}

catch(Exception e){

JOptionPane.showMessageDialog(this, "Time interval must not be zero.");

}

}

return averageCarPassing;

}

//Convert the user's input string to integer and assgin the converted value to perdefined variables.

public boolean prepareData(){

boolean b=false;

if(data_Validation()){

preDeterminedThroughputTime=Integer.parseInt(jtxtThroughputtime.getText().trim());

averagePaymentTime=Integer.parseInt(jtxtAverageTimepayment.getText().trim());

averageNoOfCar=calculateAverageCarPassing();

b=true;

}

return b;

}

//Return averagePaymentTime integer

protected int getAveragePaymentTime(){

return averagePaymentTime;

}

//Return getPredefinedThroughputTime integer

protected int getPredefinedThroughputTime(){

return preDeterminedThroughputTime;

}

//Return averageNoOfCar integer.

protected int getAverageNoOfCars(){

return averageNoOfCar;

}

//Set the simulated value to jtxtNooftollbooth.

protected void setNoOfTollbooths(int noOfBooths){

jtxtNooftollbooth.setText(noOfBooths+"");

}

private void jcboMonthItemStateChanged(java.awt.event.ItemEvent evt) {

int year=Integer.parseInt(jcboYear.getSelectedItem().toString());

int month=Integer.parseInt(jcboMonth.getSelectedItem().toString());

fillDay(year, month);

}

private void jcboYearItemStateChanged(java.awt.event.ItemEvent evt) {

int year=Integer.parseInt(jcboYear.getSelectedItem().toString());

int month=Integer.parseInt(jcboMonth.getSelectedItem().toString());

fillDay(year, month);

}

private void formInternalFrameActivated(javax.swing.event.InternalFrameEvent evt) {

fillHighway();

}

private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {

exit();

}

private void jmnuSaveSimulationActionPerformed(java.awt.event.ActionEvent evt) {

save_Data();

clearData();

JOptionPane.showMessageDialog(this, "Data has been saved successfully.");

}

3.2.2.1 Testing for data insertion of Simulation form

Test data

Simulation ID= S-0000003

Simulation date=8/5/2010

Simulation time=9:21:1 am

No of cars= 8

Duration = 1

Predefined throughput time = 20

Average Time payment= 8

No of tollbooths to be built =4

Expected result

Insert the user input value into the database table named Simulation.

Actual result

Action

Click the save menu item from File menu bar.

3.2.2.2 Testing for data validation of simulation form

Test description: If users try to insert into the database table without data, the following result will occur

Task 4

Design, implementation, and testing for storing the results of the highway tollbooth simulation

4.1 Database design

4.1.1 Normalization

Gathered data

Highway ID

Highway No

Exit Point Name

Simulation ID

Simulation Date

Simulation Time

No of car passing

Duration

Throughput time

Averaged toll payment time

No of tollbooths to be built

By following normalization rule, two third normal forms are obtained.

Third normal form

Highway third normal form

Highway ID (primary key)

Highway No

Exit Point Name

Simulation third normal form

Simulation ID (primary key)

Highway ID *

Simulation Date

Simulation Time

No of cars passing

Duration

Throughput time

Average payment time

No of tollbooths to be built

4.1.2 Entity relationship diagram

Again, it is found that there is one to many relationship between Highway and Simulation. According to this, the ERD (entity relationship diagram) will be,

4.2 Database Implementation

For storing the results of this Highway tollbooths simulation, I choose Microsoft Access to implement database.

4.3 Testing of the created database implementation

After implementing database in Microsoft access 2007, I insert data filed in the Highway and Simulation tables for testing them.

Task 5

Implementation and Testing

5.1 System implementation

Main_Form Class

Vairables

private int tollpaymenttime,predefinedthroughputtime,averagenoofcar,waitTime,tollbothindex=0,x=0,index;

private ArrayList<TollBooth> toll=new ArrayList<TollBooth>(5);

private boolean simulationControl=true;

Simulation sim=new Simulation();

Methods

//Make a connection to the database.

protected static Connection databaseConnection(){

Connection con=null;

File file=new File("TollboothSimulation.accdb");

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+file.getAbsolutePath());

}

catch(Exception e){

e.printStackTrace();

}

return con;

}

//Exit

private void exit(){

int option=JOptionPane.showConfirmDialog(this, "Are you sure to exit?", "Exit", JOptionPane.YES_NO_OPTION);

if(option==JOptionPane.YES_OPTION){

dispose();

}

else{

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

}

}

//Create tollbooths

public void createtollbooths(){

TollBooth tb=new TollBooth(tollpaymenttime);

tb.setBounds(x, 0, 240, 700);

jdesktop.add(tb);

toll.add(tb);

tollbothindex++;

x+=240;

}

//setting data

public void setData(){

if(sim.prepareData()){

tollpaymenttime=sim.getAveragePaymentTime();

predefinedthroughputtime=sim.getPredefinedThroughputTime();

averagenoofcar=sim.getAverageNoOfCars();

}

else{

JOptionPane.showMessageDialog(this, "There is no data to simulate.");

}

}

//Check throughpput time

private boolean checkThroughputTime(){

boolean b=false;

if(toll.size()==1){

if(toll.get(0).getThroughputTime()>predefinedthroughputtime){

b=true;

}

}

else if(toll.size()==2){

if(toll.get(0).getThroughputTime()>predefinedthroughputtime&&toll.get(1).getThroughputTime()>predefinedthroughputtime){

b=true;

}

}

else if(toll.size()==3){

if(toll.get(0).getThroughputTime()>predefinedthroughputtime&&toll.get(1).getThroughputTime()>predefinedthroughputtime&&toll.get(2).getThroughputTime()>predefinedthroughputtime){

b=true;

}

}

else if(toll.size()==4){

if(toll.get(0).getThroughputTime()>predefinedthroughputtime&&toll.get(1).getThroughputTime()>predefinedthroughputtime&&toll.get(2).getThroughputTime()>predefinedthroughputtime&&toll.get(3).getThroughputTime()>predefinedthroughputtime){

b=true;

}

}

return b;

}

//Find which tollbooth to allow coming vehicle

private int searchingindex(){

int i=0;

ArrayList al=new ArrayList();

ArrayList altemp=new ArrayList();

for (int j=0;j<tollbothindex;j++){

al.add(toll.get(j).alvehicle.size());

altemp.add(toll.get(j).alvehicle.size());

}

Collections.sort(al);

i=altemp.indexOf(al.get(0));

return i;

}

5.2 Testing with screen shots

This software is all about simulation for tollbooths to determine the number of tollbooths that might be required at any particular motorway exit point. It is hoped that results from running the simulation would:

1. Determine the maximum number of tollbooths to be built at particular exit points

2. Determine the number of these booths that need to be open, depending on the traffic conditions, at a particular time.

Five steps are needed to do the complete system testing. The following five steps are

1. Opening the software

2. Entering data in the highway form

3. Entering data in the simulation form

4. Starting the simulation and saving the simulated result

5. Opening the report form

Step 1 Opening the software

The first step is to open the software and check whether the software opens or not.

Action: Clicking the software icon.

Expected result: Highway tollbooth simulation main form will appear.

Evidence: Fig 5.2.1

Step 2 Entering data into the Highway form

Second step is to open the Highway form from the Main form by clicking the Highway form from the main menu.

Action: Click the Highway form from the main menu bar.

Expected result: Highway form will appear.

After the form has been opened, enter data into the form and save the result.

Action: Clicking Save from the File menu

Tested data

1. Highway ID = H-00005

2. Highway No = Yangon-Taungyi 1

3. Exit Point Name = Taunggyi

Expected result: Data will be saved in the database.

Evidence

Step 3 Entering data into the simulation form

Open the Simulation form and enter data into the simulation form.

Tested data:

1. Simulation ID = S-0000004

2. Highway No = YB-1

3. Date = 13/5/2010

4. Time = 9:30:1 am

5. No of car = 6

6. Time interval in minutes = 1

7. Predetermined throughput time = 25

8. Average payment time = 10

Evidence:

Step 4 Starting the simulation and saving the simulated result

Start the simulation with inserted data from step 3

Action: Click the Start Simulation from the main menu.

Expected result: Simulation will run with Graphical component.

Evidence:

Step 5 Opening the report form

This step is about to call the Report form and view the report.

Action

1. Click the Show report from the main menu

2. Choose the Highway No from the combo box

3. And then press the Show report button

Expected Result: Report form will appear and report will be shown.

Evidence:

Task 6 Complete System Testing

Action: Clicking the software icon.

Expected result: Highway tollbooth simulation main form will appear.

Evidence:

Step 2 Entering data into the Highway form

Second step is to open the Highway form from the Main form by clicking the Highway form from the main menu.

Action: Click the Highway form from the main menu bar.

Expected result: Highway form will appear.

Evidence:

After the form has been opened, enter data into the form and save the result.

Action: Clicking Save from the File menu

Tested data

4. Highway ID = H-00005

5. Highway No = Yangon-Taungyi 1

6. Exit Point Name = Taunggyi

Expected result: Data will be saved in the database.

Evidence

Step 3 Entering data into the simulation form

Open the Simulation form and enter data into the simulation form.

Tested data:

9. Simulation ID = S-0000004

10. Highway No = YB-1

11. Date = 13/5/2010

12. Time = 9:30:1 am

13. No of car = 6

14. Time interval in minutes = 1

15. Predetermined throughput time = 25

16. Average payment time = 10

Evidence:

Step 4 Starting the simulation and saving the simulated result

Start the simulation with inserted data from step 3

Action: Click the Start Simulation from the main menu.

Expected result: Simulation will run with Graphical component.

Evidence:

Step 5 Opening the report form

This step is about to call the Report form and view the report.

Action

4. Click the Show report from the main menu

5. Choose the Highway No from the combo box

6. And then press the Show report button

Expected Result: Report form will appear and report will be shown.

Evidence:

Task 7 User Guide

Introduction

This software is all about simulation for tollbooths to determine the number of tollbooths that might be required at any particular motorway exit point. It is hoped that results from running the simulation would:

3. Determine the maximum number of tollbooths to be built at particular exit points

4. Determine the number of these booths that need to be open, depending on the traffic conditions, at a particular time.

To use the software efficiently, there are five steps you need to follow. The following five steps are:

1. Opening the software

2. Entering data into the highway form

3. Entering data into the simulation form

4. Starting the simulation and saving the simulated result

5. Opening the report form

Step 1 Opening the software

After opening the software, the following user interface will appear.

Step 2 Entering data into the Highway form

In the next step, you have to first open the Highway form from the main menu, and Highway form will appear on the main screen.

In the Highway input form, you can enter a new highway on which you want to run simulation and save your newly entered Highway for future reference. You can also delete existing highway from the database which you don't no more require.

Step 3 Entering data into the Simulation form

After successfully performing step 2, you have to open the Simulation form from the main menu.

In the Simulation form, you first choose the Highway from the Highway No combo box. Secondly, you can choose date and time on which you perform Simulation from the Simulation Date and Time section. Thirdly, number of cars passing in particular time interval needs to be entered for the simulation. After that, you need to enter predetermined throughput time and average toll payment time for a car to determine whether the new gate needs to be opened or built.

Step 4 Starting the simulation and saving the simulated result

After step 3, click the Start Simulation from the main menu bar and the simulation will start with the graphical component. After waiting for the particular amount of time, you can click the Stop Simulation if you satisfy the simulation result. After you have clicked the Stop Simulation, the calculated total no of tollbooths needed to be built or opened will appear on the no of toll booths to be built Text box. And After that, you can save your simulation result in the database by clicking the Save Simulation result.

Step 5 Opening the report form

You can view the report of the simulation result about a chosen highway by clicking Show Report from the main menu bar. On the report form, you first have to choose the Highway No that you want to view about and click Show report button.

The above five steps are the steps you need to follow through to manipulate the software efficiently.

Task 8 Installation Note

On the compiled program folder of dist, double clicking the Computer Simulation for toll motorways.jar file will become the program to be runned.

Requirement

System requirements

Operating system: any platform with JRE (Java Runtime Environment) installed.

CPU: Intel(R) Pentium(R) 4 processor supporting HT Technology or higher

(Recommended: Intel(R) Core(TM)2 Duo processor or higher)

Main Memory: Windows(R) XP : at least 512MB (Recommended: at least 1GB)

Windows Vista(TM) : at least 1GB (Recommended: at least 2GB)

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.