0% found this document useful (0 votes)
49 views27 pages

csc186 Group Project Report Bus Reservation System

Uploaded by

umarzikri00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views27 pages

csc186 Group Project Report Bus Reservation System

Uploaded by

umarzikri00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

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@gmail.com)
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@gmail.com)


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@gmail.com)


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@gmail.com)


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@gmail.com)


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@gmail.com)


lOMoARcPSD|43132498

UML DIAGRAM

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

USE CASE DIAGRAM

Downloaded by Umar Zikri (umarzikri00@gmail.com)


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@gmail.com)


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
{
this.name = name;
this.phoneNum = phoneNum;
this.age = age;
}
public void setCustomer(String a, String b, int c) //mutator
{
this.name = a;
this.phoneNum = b;
this.age = 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@gmail.com)


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 >> " +
customer.toString() +
"\nDestination : " + destination;
}
}

10

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

CLASS LOCAL

import java.text.DecimalFormat;
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)
{
super.setTicket(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(super.getDestination().equals("TBS"))
charge = 20 * super.getQuantity();
else if(super.getDestination().equals("Terminal Melaka
Sentral"))
charge = 15 * super.getQuantity();
else if(super.getDestination().equals("Kuala Perlis bus
Terminal"))
charge = 70 * super.getQuantity();
else //Kuala Terengganu Bus Station
charge = 30 * super.getQuantity();

//ticket with insurance


if(getInsurance().equalsIgnoreCase("Yes"))
insuredCharge = charge + (1.5 * super.getQuantity());

11

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

else
insuredCharge = charge;

//ticket with discount + insurance


if(customer.getAge() <= 7)
total = insuredCharge - (insuredCharge * 0.20);
else if(customer.getAge() >= 60)
total = insuredCharge - (insuredCharge * 0.25);
else
total = insuredCharge;

return total;
}

public String toString() //toString for Local


{
return super.toString() +
"\nInsurance:" + getInsurance() +
"\nTotal Price: RM " + df.format(calculatePrice());
}

12

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

CLASS ISLAND

import java.text.DecimalFormat;
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
{
super.setTicket(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(super.getDestination().equals("Pulau Kapas"))
charge = 100 * super.getQuantity();
else if(super.getDestination().equals("Pulau Perhentian"))
charge = 150 * super.getQuantity();
else if(super.getDestination().equals("Pulau Tioman"))
charge = 200 * super.getQuantity();
else //PULAU LANGKAWI
charge = 300 * super.getQuantity();

//ticket with discount + insurance


if(customer.getAge() <= 7)
total = charge - (charge * 0.20);

13

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

else if(customer.getAge() >= 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 super.toString() +
"\nMemberShip: " + membership +
"\nTotal Price: RM " + df.format(calculatePrice());
}
}

14

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

CLASS BUS RESERVATION (MAIN PROGRAM)

import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
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("reservation.txt");


BufferedReader br = new BufferedReader(fr);

String line;
Ticket [] t = new Ticket[100];
int [] array = new int[100];
int i = 0;

while((line = br.readLine())!=null)
{
StringTokenizer st = new StringTokenizer(line,",");
String choice = st.nextToken();
String cName = st.nextToken();
int cAge = Integer.parseInt(st.nextToken());
String cPhone = st.nextToken();

Customer c = new Customer(cName, cPhone, cAge);


if(choice.equalsIgnoreCase("L"))
{
String tDestination = st.nextToken();
int tQty = Integer.parseInt(st.nextToken());
String tInsurance = st.nextToken();
array[i] = tQty;
t[i] = new Local(tQty, c, tDestination,
tInsurance);
}
else
{
String tDestination = st.nextToken();
int tQty = Integer.parseInt(st.nextToken());

15

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

String tMem = st.nextToken();


boolean tMember = false;
if(tMem.equalsIgnoreCase("Yes"))
tMember = true;
array[i] = tQty;
t[i] = new Island(tQty, c, tDestination, tMember);
}
i++;
}

PrintWriter pw = new PrintWriter("bus.txt");


pw.println(" LIST
OF ALL CUSTOMERS [MANAGEMENT PURPOSE]
");
pw.println("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
pw.println(String.format("%-25s%-12s%-20s%-30s%-20s%-20s%-
20s","NAME","AGE","PHONE
NO","DESTINATION","QUANTITY","INSURANCE","MEMBERSHIP"));
pw.println("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
for(int a=0;a<i;a++)
{
if(t[a] instanceof Local)
{
Local l = (Local)t[a];
pw.println(String.format("%-25s%-12s%-20s%-30s%-
20s%-20s%-
20s",l.customer.getName(),l.customer.getAge(),l.customer.getPhoneNum()
,l.getDestination(),l.getQuantity(),l.getInsurance(),"NA"));
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
pw.println(String.format("%-25s%-12s%-20s%-30s%-
20s%-20s%-
20s",is.customer.getName(),is.customer.getAge(),is.customer.getPhoneNu
m(),is.getDestination(),is.getQuantity(),"NA",is.boolString()));
}
}

//total & average of ticket price (all customer)

16

Downloaded by Umar Zikri (umarzikri00@gmail.com)


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 += l.calculatePrice();
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
totalIs += is.calculatePrice();
}
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(l.getQuantity() > max)
max = l.getQuantity();
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
if(is.getQuantity() > max)
max = is.getQuantity();
}
if(t[a] instanceof Local && t[a] instanceof Island)
{
Local l = (Local)t[a];
Island is = (Island)t[a];
if(l.getQuantity()>is.getQuantity())
max = l.getQuantity();
else
max = is.getQuantity();
}
}

17

Downloaded by Umar Zikri (umarzikri00@gmail.com)


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(l.getQuantity() < min)
min = l.getQuantity();
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
if(is.getQuantity() < min)
min = is.getQuantity();
}
if(t[a] instanceof Local && t[a] instanceof Island)
{
Local l = (Local)t[a];
Island is = (Island)t[a];
if(l.getQuantity()<is.getQuantity())
min = l.getQuantity();
else
min = is.getQuantity();
}
}
pw.println("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
pw.println(String.format("%-25s%-12s%-20s%-30s%-20s%-36s%-
20s","TOTAL(RM)","","","","","",df.format(total)));
pw.println(String.format("%-25s%-12s%-20s%-30s%-20s%-36s%-
20s","Average(RM)","","","","","",dt.format(average)));
pw.println("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");
pw.println(String.format("%-25s%-12s%-20s%-30s%-20s%-39s%-
20s","Maximum number of Ticket","","","","","",max));
pw.println(String.format("%-25s%-12s%-20s%-30s%-20s%-39s%-
20s","Minimum number of Ticket","","","","","",min));
pw.println("----------------------------------------------
----------------------------------------------------------------------
----------------------|---------------|");

//search customer

18

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

String search = JOptionPane.showInputDialog("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(l.customer.getName().equals(search))
{
found = true;
indexFound = a;
}
}
else if(t[a] instanceof Island)
{
Island is = (Island)t[a];
if(is.customer.getName().equals(search))
{
found = true;
indexFound = a;
}
}
}
if(found)//updating
{
t[indexFound].customer.setCustomer("Aria Jenne","011-
2345567",4);
System.out.println("THE NAME YOU SEARCHED FOR WAS
FOUND AND RECORD UPDATED!");
}
else
System.out.println("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@gmail.com)


lOMoARcPSD|43132498

array[x] = array[x+1];
array[x+1] = swap;
}
}
}

//count for ticket quantity


int count = 0;
for(int x = 0; x < t.length; x++)
{
if(array[x] > 0)
{
count += t[x].getQuantity();
}
}

System.out.println("\n
LIST OF ALL CUSTOMERS [AFTER SORTING]
");
System.out.println("--------------------------------------
----------------------------------------------------------------------
-----------");
for(int c=0;c<n;c++)
{
if(c==0)
{
for(int j=0;j<n;j++)
{
if(array[c] == t[j].getQuantity())
System.out.println(t[j].toString());
}
}
else if(array[c] != array[c-1])
{
for(int j=0;j<n;j++)
{
if(array[c] == t[j].getQuantity())
System.out.println(t[j].toString());
}
}
}

20

Downloaded by Umar Zikri (umarzikri00@gmail.com)


lOMoARcPSD|43132498

System.out.println("\nThe number of tickets bought by all


customers are : " + count + " in total.");

System.out.println("--------------------------------------
----------------------------------------------------------------------
-----------");
pw.close();
br.close();
}
catch(FileNotFoundException e){System.out.println("File
cannot be found!");}

catch(Exception e){System.out.println("Cannot read the


Data!");}
}
}

21

Downloaded by Umar Zikri (umarzikri00@gmail.com)


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@gmail.com)


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@gmail.com)


lOMoARcPSD|43132498

24

Downloaded by Umar Zikri (umarzikri00@gmail.com)


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@gmail.com)


lOMoARcPSD|43132498

REFERENCES

1) Tech Raj, Jan 3, 2017, Sorting Arrays in Java - Tutorial | Selection


Sort and Bubble Sort, Youtube.
https://youtu.be/ZQ8AaxHnAb0
2) Lucid Software, Feb 8, 2018, UML Use Case Diagram Tutorial, Youtube.
https://youtu.be/zid-MVo7M-E
3) UML Class Diagram Tutorial – Visual Paradigm.
https://www.visual-paradigm.com/guide/uml-unified-modeling-
language/uml-class-diagram-tutorial/

26

Downloaded by Umar Zikri (umarzikri00@gmail.com)

You might also like