lOMoARcPSD|43132498
CSC186 Group Project Report (BUS Reservation System)
introduction to java (Universiti Teknologi MARA)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
CSC186: OBJECT-ORIENTED PROGRAMMING
GROUP PROJECT REPORT
Group : JCS1102A
Lecturer’s Name : PUAN ZURIATI BINTI ISMAIL @ KHORI
GROUP MEMBER STUDENT ID
ALIFF WAFIUDDIN BIN MOHD AZIZUL KYUSYAIRI 2021611452
MUHAMMAD ‘IRFAN BIN RAHMAT 2021877566
NUR AIN BINTI MOHD SOFIAN 2021631594
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
TABLE OF CONTENT
NO TOPICS PAGE
1 ORGANIZATIONAL STRUCTURE 3
2 PROJECT TITLE 4
3 INTRODUCTION 4
4 OBJECTIVES 5
5 LIST OF PROCESSINGS/OBJECTIVES 5
6
6 UML DIAGRAM
7
7 USE CASE DIAGRAM
8
8 INPUT DATA
9 - 21
9 CLASS DEFINITION OF INHERITANCE AND POLYMORPHISM
22 – 25
10 INFORMATIONS DISPLAY AND INTERFACE SAMPLES
26
11 REFERENCES
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
ORGANIZATIONAL STRUCTURE
ALIFF WAFIUDDIN BIN MOHD AZIZUL
KYUSYAIRI
• Team project leader
• Creating UML Diagram
• Code for Customer, Local class
• Do sort numbers of ticket in
ascending order (list of
processing)
• Write a project report
MUHAMMAD ‘IRFAN BIN NUR AIN BINTI MOHD
RAHMAT SOFIAN
• Team project member • Team project member
• Creating UML diagram • Creating UML
• Do coding for Ticket (subclasses) and use
and Island class case diagram
• Do count number of • Do coding for Main
tickets (list of program class
processing) • Do total and average,
• Do search customer’s minimum and
name in the system maximum of ticket (list
• Write a project report of processing)
• Write a project report
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
1. Project Title:
Bus Ticket Reservation
2. Introduction:
Ticket Nation is one of the new projects that had been assigned to provide the reservation
bus ticket platform for people or traveler who want to travel all over Malaysia. The platform
enables traveler to reserve and order the ticket to make sure traveler will have the best
travel experience in their life. This system will provide user to choose the destination that
they want to go as they can arrive at the right place at the exact time.
To make sure the system will provide what the customer wants, they will need to
provide their name, age, phone number and the quantity of ticket. By fulfill all this
requirement, this system will give customer the ticket to make sure they will have
permission to have a bus service to make sure they can go travel to the destination that
they want and arrive safely without any problem or issues. As stated in the UML Diagram
on page 6 in this proposal as the information needed in the development of Ticket Nation
bus ticket reservation system. The following class Customer defines all the details required
for the user information while class Ticket will define all the details for the ticket info for
customer. The system will be able to count number of tickets for each destination,
determine the maximum and minimum number of ticket that customer have bought,
calculate average ticket price, and calculate the total price of tickets. Besides that,
discount also provided for customer which are count by their age which is children will
enjoy 20% discount while elder will entitled 25% discount.
In the end of the system, it will display all the user information that user had enter.
So, user will know that the transaction that they have made was successful. The final
receipt will show the final price, customer’s detail, and the bus route.
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
3. Lists of Processing/Objectives:
i. Count the number of tickets for different destinations that the customers decided to go.
ii. Count the maximum and minimum number of tickets the customers bought.
iii. Calculate the average of ticket's price for all customers.
iv. Calculate the price of the tickets for different destinations with discount and without
discount:
- Children: 20%
- Elder: 25%
v. Calculate total price of tickets for all customers.
vi. Search customer's name and update customer's information.
vii. Sort the customers based on the quantity of tickets in ascending order.
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
UML DIAGRAM
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
USE CASE DIAGRAM
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
INPUT DATA
For input, we use txt file as there are many customer’s input to be insert in our system.
We use bufferedReader and StringTokenizer for reading txt file.
We also use a JOptionPane for user to search customer’s name to make sure they are in our
system.
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
CLASS DEFINITION OF INHERITANCE AND POLYMORPHISM
CLASS CUSTOMER
public class Customer
{
private String name, phoneNum;
private int age;
public Customer(String name, String phoneNum, int age)
//parameterized constructor
{
[Link] = name;
[Link] = phoneNum;
[Link] = age;
}
public void setCustomer(String a, String b, int c) //mutator
{
[Link] = a;
[Link] = b;
[Link] = c;
}
//accessor
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String getPhoneNum()
{
return phoneNum;
}
public String toString() //toString for Customer
{
return "\nCustomer Name : " + name +
"\nCustomer age : " + age +
"\nPhone Number : " + phoneNum;
}
}
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
CLASS TICKET
public abstract class Ticket
{
protected int quantity;
protected Customer customer;
protected String destination;
public Ticket(int qty, Customer cust, String desti)
{
quantity = qty;
customer = cust;
destination = desti;
public void setTicket(int a, Customer b, String c)
{
quantity = a;
customer = b;
destination = c;
}
public int getQuantity()
{
return quantity;
}
public Customer getDetails()
{
return customer;
}
public String getDestination()
{
return destination;
}
public abstract double calculatePrice();
public String toString() //toString for Ticket
{
return "\nCustomer Details >> " +
[Link]() +
"\nDestination : " + destination;
}
}
10
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
CLASS LOCAL
import [Link];
public class Local extends Ticket
{
private String insurance;
DecimalFormat df = new DecimalFormat("0.00");
public Local(int qty, Customer cust, String desti, String ins)
{
super(qty, cust, desti);
insurance = ins;
}
public void setLocal(int qty, Customer cust, String desti, String
newIns)
{
[Link](qty, cust, desti);
insurance = newIns;
}
public String getInsurance()
{
return insurance;
}
public double calculatePrice()
{
double charge = 0.0, total = 0.0, insuredCharge = 0;
//base ticket price
if([Link]().equals("TBS"))
charge = 20 * [Link]();
else if([Link]().equals("Terminal Melaka
Sentral"))
charge = 15 * [Link]();
else if([Link]().equals("Kuala Perlis bus
Terminal"))
charge = 70 * [Link]();
else //Kuala Terengganu Bus Station
charge = 30 * [Link]();
//ticket with insurance
if(getInsurance().equalsIgnoreCase("Yes"))
insuredCharge = charge + (1.5 * [Link]());
11
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
else
insuredCharge = charge;
//ticket with discount + insurance
if([Link]() <= 7)
total = insuredCharge - (insuredCharge * 0.20);
else if([Link]() >= 60)
total = insuredCharge - (insuredCharge * 0.25);
else
total = insuredCharge;
return total;
}
public String toString() //toString for Local
{
return [Link]() +
"\nInsurance:" + getInsurance() +
"\nTotal Price: RM " + [Link](calculatePrice());
}
12
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
CLASS ISLAND
import [Link];
public class Island extends Ticket
{
private boolean membership;
DecimalFormat df = new DecimalFormat("0.00");
public Island(int a,Customer b, String c, boolean d)
//parameterized constructor
{
super(a, b, c);
membership = d;
}
public void setIsland(int a,Customer b, String c, boolean d)
//mutator
{
[Link](a, b, c);
membership = d;
}
//accessor
public boolean getMembership()
{
return membership;
}
public double calculatePrice() //calculation
{
double charge = 0.0, member = 0.0, total = 0.0;
//base ticket price
if([Link]().equals("Pulau Kapas"))
charge = 100 * [Link]();
else if([Link]().equals("Pulau Perhentian"))
charge = 150 * [Link]();
else if([Link]().equals("Pulau Tioman"))
charge = 200 * [Link]();
else //PULAU LANGKAWI
charge = 300 * [Link]();
//ticket with discount + insurance
if([Link]() <= 7)
total = charge - (charge * 0.20);
13
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
else if([Link]() >= 60)
total = charge - (charge * 0.25);
else
total = charge;
//ticket with membership discount
if(membership)
member = total - (total * 0.15);
else
member = total;
return member;
}
public String boolString()
{
if(membership)
return "Yes";
else
return "No";
}
public String toString() //toString for Island - Printer Method
{
return [Link]() +
"\nMemberShip: " + membership +
"\nTotal Price: RM " + [Link](calculatePrice());
}
}
14
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
CLASS BUS RESERVATION (MAIN PROGRAM)
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class BusReservation
{
public static void main(String[] args) throws IOException
{
try
{
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormat dt = new DecimalFormat("0.00");
FileReader fr = new FileReader("[Link]");
BufferedReader br = new BufferedReader(fr);
String line;
Ticket [] t = new Ticket[100];
int [] array = new int[100];
int i = 0;
while((line = [Link]())!=null)
{
StringTokenizer st = new StringTokenizer(line,",");
String choice = [Link]();
String cName = [Link]();
int cAge = [Link]([Link]());
String cPhone = [Link]();
Customer c = new Customer(cName, cPhone, cAge);
if([Link]("L"))
{
String tDestination = [Link]();
int tQty = [Link]([Link]());
String tInsurance = [Link]();
array[i] = tQty;
t[i] = new Local(tQty, c, tDestination,
tInsurance);
}
else
{
String tDestination = [Link]();
int tQty = [Link]([Link]());
15
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
String tMem = [Link]();
boolean tMember = false;
if([Link]("Yes"))
tMember = true;
array[i] = tQty;
t[i] = new Island(tQty, c, tDestination, tMember);
}
i++;
}
PrintWriter pw = new PrintWriter("[Link]");
[Link](" LIST
OF ALL CUSTOMERS [MANAGEMENT PURPOSE]
");
[Link]("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
[Link]([Link]("%-25s%-12s%-20s%-30s%-20s%-20s%-
20s","NAME","AGE","PHONE
NO","DESTINATION","QUANTITY","INSURANCE","MEMBERSHIP"));
[Link]("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
for(int a=0;a<i;a++)
{
if(t[a] instanceof Local)
{
Local l = (Local)t[a];
[Link]([Link]("%-25s%-12s%-20s%-30s%-
20s%-20s%-
20s",[Link](),[Link](),[Link]()
,[Link](),[Link](),[Link](),"NA"));
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
[Link]([Link]("%-25s%-12s%-20s%-30s%-
20s%-20s%-
20s",[Link](),[Link](),[Link]
m(),[Link](),[Link](),"NA",[Link]()));
}
}
//total & average of ticket price (all customer)
16
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
double total = 0.0, totalLo = 0.0, totalIs = 0.0, average
= 0.0;
for(int a=0;a<i;a++)
{
if(t[a] instanceof Local)//calculate total
{
Local l = (Local)t[a];
totalLo += [Link]();
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
totalIs += [Link]();
}
total = totalLo + totalIs;
average = total/i;
}
//max quantity of ticket
int max = -9999;
for(int a=0;a<i;a++)
{
if(t[a] instanceof Local)
{
Local l = (Local)t[a];
if([Link]() > max)
max = [Link]();
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
if([Link]() > max)
max = [Link]();
}
if(t[a] instanceof Local && t[a] instanceof Island)
{
Local l = (Local)t[a];
Island is = (Island)t[a];
if([Link]()>[Link]())
max = [Link]();
else
max = [Link]();
}
}
17
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
//min quantity of ticket
int min = 9999;
for(int a=0;a<i;a++)
{
if(t[a] instanceof Local)
{
Local l = (Local)t[a];
if([Link]() < min)
min = [Link]();
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
if([Link]() < min)
min = [Link]();
}
if(t[a] instanceof Local && t[a] instanceof Island)
{
Local l = (Local)t[a];
Island is = (Island)t[a];
if([Link]()<[Link]())
min = [Link]();
else
min = [Link]();
}
}
[Link]("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
[Link]([Link]("%-25s%-12s%-20s%-30s%-20s%-36s%-
20s","TOTAL(RM)","","","","","",[Link](total)));
[Link]([Link]("%-25s%-12s%-20s%-30s%-20s%-36s%-
20s","Average(RM)","","","","","",[Link](average)));
[Link]("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
[Link]([Link]("%-25s%-12s%-20s%-30s%-20s%-39s%-
20s","Maximum number of Ticket","","","","","",max));
[Link]([Link]("%-25s%-12s%-20s%-30s%-20s%-39s%-
20s","Minimum number of Ticket","","","","","",min));
[Link]("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
//search customer
18
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
String search = [Link]("Search
customer's name : ");
boolean found = false;
int indexFound = 0;
for(int a=0;a<i;a++)
{
if(t[a] instanceof Local)
{
Local l = (Local)t[a];
if([Link]().equals(search))
{
found = true;
indexFound = a;
}
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
if([Link]().equals(search))
{
found = true;
indexFound = a;
}
}
}
if(found)//updating
{
t[indexFound].[Link]("Aria Jenne","011-
2345567",4);
[Link]("THE NAME YOU SEARCHED FOR WAS
FOUND AND RECORD UPDATED!");
}
else
[Link]("THE NAME YOU SEARCHED FOR IS NOT EXIST
AND RECORD NOT FOUND!");
//sort customers based on quantity of ticket
int swap = 0, n = i;
for(int a=0;a<(n-1);a++)
{
for(int x=0;x<(n-a-1);x++) //ascending order
{
if(array[x]>array[x+1])
{
swap = array[x];
19
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
array[x] = array[x+1];
array[x+1] = swap;
}
}
}
//count for ticket quantity
int count = 0;
for(int x = 0; x < [Link]; x++)
{
if(array[x] > 0)
{
count += t[x].getQuantity();
}
}
[Link]("\n
LIST OF ALL CUSTOMERS [AFTER SORTING]
");
[Link]("--------------------------------------
----------------------------------------------------------------------
-----------");
for(int c=0;c<n;c++)
{
if(c==0)
{
for(int j=0;j<n;j++)
{
if(array[c] == t[j].getQuantity())
[Link](t[j].toString());
}
}
else if(array[c] != array[c-1])
{
for(int j=0;j<n;j++)
{
if(array[c] == t[j].getQuantity())
[Link](t[j].toString());
}
}
}
20
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
[Link]("\nThe number of tickets bought by all
customers are : " + count + " in total.");
[Link]("--------------------------------------
----------------------------------------------------------------------
-----------");
[Link]();
[Link]();
}
catch(FileNotFoundException e){[Link]("File
cannot be found!");}
catch(Exception e){[Link]("Cannot read the
Data!");}
}
}
21
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
DISPLAY INFORMATION AND SAMPLE INTERFACES
Diagram below shows an output sample that using FileWriter and BufferedWriter method.
Diagram below shows a pop out that using JOptionPane for management to fill in the
customer’s name to search customer’s name if their name is in the system or not.
This is the output if customer’s name was found and it will updated the customer’s name and
phone number.
22
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
While this is the output if customer’s name does not exist in the system
This is the output sample that had been sorting in ascending order with a total count of ticket
reservation
23
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
24
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
In the end of program, it is show that the total ticket bought by all customers which are 54
tickets. All the sequence in the diagram is sorted by the quantity of tickets which is sort in
ascending order
25
Downloaded by Umar Zikri (umarzikri00@[Link])
lOMoARcPSD|43132498
REFERENCES
1) Tech Raj, Jan 3, 2017, Sorting Arrays in Java - Tutorial | Selection
Sort and Bubble Sort, Youtube.
[Link]
2) Lucid Software, Feb 8, 2018, UML Use Case Diagram Tutorial, Youtube.
[Link]
3) UML Class Diagram Tutorial – Visual Paradigm.
[Link]
language/uml-class-diagram-tutorial/
26
Downloaded by Umar Zikri (umarzikri00@[Link])