0% found this document useful (0 votes)
1K views38 pages

Final Report Csc248

Uploaded by

2024905115
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)
1K views38 pages

Final Report Csc248

Uploaded by

2024905115
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/ 38

UITM SEGAMAT, JOHOR

FACULTY OF COMPUTER AND MATHEMATICAL SCIENCES

FINAL REPORT
OF
KERETA API TANAH MELAYU BERHAD DATA MANIPULATION

GROUP PROJECT CSC248

GROUP MEMBER STUDENT ID

NURUL ELIZWANI BINTI KAMSANI 2021616054

ALIANAJWA MAISARAH BINTI AZAR 2021815376

NURUL FAQIHAH BINTI ABDUL KARIM 2021882416

GROUP: JCS1103B

LECTURER NAME: YUSNITA BINTI SOKMAN

DATE SUBMISSION: 4/12/2022

1
TABLE OF CONTENTS
____________________________________________________

Introduction of Project…………………………………………………………………………..3

Introduction of Group Members………………………………………………………………..4

Distribution of works…………………………………………………………………………….4

Complete coding of all classes…………………………………………………………………5


Class Node………………………………………………………………………………5
Class LinkedList…………………………………………………………………………9
Class Queue……………………………………………………………………………..9
Class EmptyListException…………………………………………………………….10
Class Passenger……………………………………………………………………….10
Class testKTM………………………………………………………………………….13
Class testKTMQ………………………………………………………………………..22

Sample input……………………………………………………………………………………28

Sample output………………………………………………………………………………….29
KTM……………………………………………………………………………………..29
Search Name…………………………………………………………………..29
Update Destination…………………………………………………………….30

KTMQ…………………………………………………………………………………...30

Conclusion of our finding…………………………………………………………………..34

2
INTRODUCTION OF PROJECT

Keretapi Tanah Melayu Berhad(KTMB) is known as the main rail operator in


Peninsular Malaysia. The railway network was initially constructed during the British
colonial era to carry tin. Prior to 1962, Keretapi Tanah Melayu was known as the
Federated Malay States Railways (FSMR) and the Malayan Railways Administration
(MRA). Despite being corporatized in 1992, the Malaysian government still owns all of
the organization’s shares.

The purpose of this project is to design a system for Keretapi Tanah Melayu
Berhad (KTMB) for managing the process of ticket payment and customer information.
The customers just have to insert their information first and choose any destination
available they want to go. The system will calculate the amount of payments and display
the customers information after the payment is settled. This system is also able to
count the specific type, highest payment, search , remove and update the customer’s
destination.

3
INTRODUCTION OF GROUP MEMBERS / DISTRIBUTION OF WORKS

4
COMPLETE CODING OF ALL CLASSES

a) Class Node

public class Node


{
Passenger data;
Node next;

Node (Passenger p)
{
this (p,null);
}

Node (Passenger p, Node nextNode)


{
data = p;
next=nextNode;
}

Passenger getData()
{
return data;
}

Node getNext()
{
return next;
}

5
b) Class LinkedList

public class Linkedlist


{
private Node firstNode;
private Node lastNode;
private Node currNode;

public Linkedlist()
{
firstNode = lastNode =currNode = null;
}

public void insertAtFront (Passenger insertItem)


{
if(isEmpty())
{
firstNode = lastNode= new Node(insertItem);
}
else
{
firstNode = new Node(insertItem,firstNode);
}
}

public void insertAtBack(Passenger p)


{
if(isEmpty())
firstNode = lastNode = new Node(p);
else
lastNode = lastNode.next = new Node(p);
}

//remove the first node from the List


public Passenger removeFromFront()throws EmptyListException
{
Passenger removeItem = null;
if(isEmpty())
throw new EmptyListException();
removeItem = firstNode.data; //retrieve the data

//reset the firstNode and lastNode references


if(firstNode.equals(lastNode))
firstNode = lastNode = null;
else

6
firstNode = firstNode.next;
return removeItem;
}

//remove the last node from the List


public Passenger removeFromBack()throws EmptyListException {
Passenger removeItem = null;
if(isEmpty())
throw new EmptyListException();
removeItem = lastNode.data; //retrieve the data
//reset the firstNode and lastNode references
if(firstNode.equals(lastNode))
firstNode = lastNode = null;
else {
Node current = firstNode;
while(current.next != lastNode) //not last node
current = current.next; //move to next node
lastNode = current;
current.next = null;
}
return removeItem;
}

public Passenger removeFromSecond() {


Passenger removeItem = null;
if(isEmpty() || firstNode.next == null)
removeItem = null;
else {
Node current = firstNode.next;
removeItem = current.data;
if(firstNode.next != lastNode)
{
firstNode.next = current.next;
lastNode = current.next;
current.next = null;
}
}
return removeItem;
}

//return true if the List is empty


public boolean isEmpty() { return firstNode == null; }

//return first element


public Passenger getFirst() {
if(isEmpty())

7
return null;
else
{
currNode = firstNode;
return currNode.data;
}
}

//return the next element


public Passenger getNext() {
if(currNode != lastNode) {
currNode = currNode.next;
return currNode.data;
}
else
return null;
}

public String deleteAnywhere()


{
Node currNode, previous = null;
currNode = firstNode;
String val = null;
while(currNode != null)
{
if(currNode.data.getDestination().equalsIgnoreCase("Kuala Lumpur"))
{
val =val + " " + currNode.data;
if(firstNode == lastNode)
{
firstNode = lastNode = null;
}
else if(currNode == firstNode)
{
firstNode = firstNode.next;
currNode = currNode.next;
}
else if(currNode == lastNode)
{
lastNode = previous;
lastNode.next = null;
}
else
{
currNode = currNode.next;
previous.next = currNode;

8
}
}
else
{
previous = currNode;
currNode = currNode.next;
}
}
return val;
}

public int size()


{
int size = 0;
Node currNode = firstNode;
while(currNode.next != null)
{
currNode = currNode.next;
size++;
}

return size;
}
}

9
c) Class Queue

import java.util.*;
//the Queue class with a LinkedList field

public class Queue


{
protected LinkedList list;

//queue object has been initialized


public Queue()
{
list = new LinkedList();
} //default constructor

//check whether queue object has no elemet or otherwise


public boolean isEmpty()
{
return list.isEmpty();
}//method isEmpty

//determine the no of elements in the queue object


public int size()
{
return list.size();
}// method size

//insert element at the back of the queue object


public void enqueue(Object element)
{
list.addLast(element);
} //method enqueue

//remove the front element from the queue object


public Object dequeue()
{
return list.removeFirst();
} //method dequeue

//the element at the front of the queue object has been returned
public Object front()
{
return list.getFirst();
} //method front

10
//the element at the end of the queue object has been returned
public Object rear()
{
return list.getLast();
} //method rear

} // Queue class

d) Class EmptyListException

public class EmptyListException extends RuntimeException


{
public EmptyListException()
{
super("The list is empty");
}
}

e) Class Passenger

public class Passenger


{
private String pName; //Aina binti Ahmad
private String pStatus; //Citizen or Non-Citizen
private String ktmId; //KTM card ID (KTMB1234)
//if substring(8,9) %2 =0, KTM id is female
private char category; //child(A)| adult (B) | Senior citizen (C)
private int numOfTicket; //1,2,3..
private String ticketType; // first class / middle class / business class
private double ticketPrice; // fc RM35.00 | mc RM23.00 | bc RM17.00
private String destination; // all routes in KTM map

public Passenger (String pName,String pStatus, String ktmId,char


category,int numOfTicket,String ticketType,double ticketPrice,
String destination)
{
this.pName=pName;
this.pStatus= pStatus;
this.ktmId=ktmId;
this.category=category;
this.numOfTicket = numOfTicket;

11
this.ticketType=ticketType;
this.ticketPrice=ticketPrice;
this.destination=destination;
}

/**mutator method**/
public String getPName() {return pName;}

public String getPStatus() {return pStatus;}

public String getKtmId() {return ktmId;}

public char getCategory() {return category;}

public int getNumOfTicket() {return numOfTicket;}

public String getTicketType() {return ticketType;}

public double getTicketPrice() {return ticketPrice;}

public String getDestination() {return destination;}

/**accessor method**/
public void setPName(String newPName) {pName=newPName;}

public void setPStatus (String newPStatus) {pStatus=newPStatus;}

public void setKtmId (String newKtmId) {ktmId = newKtmId;}

public void setCategory (char newCategory) {category = newCategory;}

public void setNumOfTicket (int newNumOfTicket) {numOfTicket =


newNumOfTicket;}

public void setTicketType (String newTicketType) {ticketType =


newTicketType;}

public void setTicketPrice (double newTicketPrice) {ticketPrice =


newTicketPrice;}

public void setDestination (String newDestination)


{destination=newDestination;}

/**processor method**/
public Double calcTotal()
{

12
double total = 0.0;
if (pStatus.equalsIgnoreCase ("Citizen"))
{
double updatedPrice = getTicketPrice() * 0.05;
total= getTicketPrice() - updatedPrice;
setTicketPrice(total);
}
else if (pStatus.equalsIgnoreCase("Non-Citizen"))
{
//double updatedPrice = getTicketPrice();
total = getTicketPrice();// - updatedPrice;
setTicketPrice(total);
}
return total;
}

/**printer method**/
public String toString()
{
return
(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s%-20s", ktmId,
pName,pStatus,category,numOfTicket,ticketType,ticketPrice,destination));
//getKtmId()+ getPName() + getPStatus() + getCategory() +
getNumOfTicket() +getTicketType() + getTicketPrice() + getDestination();

public String toString2()


{
return (String.format("%-15s%-32s%-15s%-20s%-20s%-20s%", ktmId,
pName,numOfTicket,ticketType,ticketPrice,destination));

13
f) Class testKTM

import java.io.*;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class testKTM
{
public static void main (String[]args)
{

java.util.Date date = new java.util.Date();

try
{
Scanner sc= new Scanner (System.in);
sc.useDelimiter("\n");

FileReader fr = new FileReader ("KTM.txt");


BufferedReader br = new BufferedReader(fr);

String dataKTM = null, name,status,id,ticketType,destination;


char category;
int tktNum=0;
double price=0.00;
Linkedlist passList = new Linkedlist();

while ((dataKTM = br.readLine()) !=null)


{
StringTokenizer st= new StringTokenizer (dataKTM, ";");

name=st.nextToken();
status=st.nextToken();
id=st.nextToken();
category=st.nextToken().charAt(0);
tktNum=Integer.parseInt(st.nextToken());
ticketType=st.nextToken();
price=Double.parseDouble(st.nextToken());
destination=st.nextToken();

Passenger p = new Passenger


(name,status,id,category,tktNum,ticketType,price,destination);
passList.insertAtFront(p);

14
}
br.close();

/**Display in tabular format**/


System.out.print ("\t\t\t\t\t\t\tKTMB PASSENGER INFORMATION AND
DATA CALCULATION");
System.out.print ("\n\t\t\t\t\t\t\t\t" + date);
Passenger p=null;
p=(Passenger)passList.getFirst();

System.out.println("\n\n--------------------------------------------------------------------------
----------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION ALL ");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));

while (p!=null)
{
System.out.println (p.toString());
p=(Passenger)passList.getNext();
}
int size = passList.size();
System.out.println("\n\t\t\tThe Size Of The List is : " + size);

System.out.print("\n-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

/** 3rd Process


* remove all Passenger from Business Class ticket that is
* Non-Citizen into new Linkedlist bcList
*/
Linkedlist temp = new Linkedlist();
Linkedlist bcList = new Linkedlist();
//p=(Passenger)passList.getFirst();
//int tfc=0;
while(!passList.isEmpty())
{
p = (Passenger)passList.removeFromBack();
if(p.getTicketType().equalsIgnoreCase("Business Class") &&

15
p.getCategory() == 'B')
{
bcList.insertAtFront(p);
}
else
{
temp.insertAtFront(p);
}
}

//restore
while (!temp.isEmpty())
{
passList.insertAtFront(temp.removeFromBack());
}

p=(Passenger)bcList.getFirst();

System.out.println("\n\n--------------------------------------------------------------------------
----------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION BC_LIST
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));

while (p != null)
{
System.out.println (p.toString());
p=(Passenger)bcList.getNext();
}

System.out.print("\n-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

/** 4th process


* Calculate the amount from each ticket and sum up the total
*/
System.out.print ("\n\n\n\t\t\t\t\t\t\t\t\t<< DATA CALCULATION >>");
int afc = 0;

16
int amc = 0;
int abc = 0;
p=(Passenger)passList.getFirst();
while (p!=null)
{
if (p.getTicketType().equalsIgnoreCase ("First Class"))
{
afc+=p.getNumOfTicket();
//afc++;
}
else if (p.getTicketType().equalsIgnoreCase("Middle Class"))
{
amc+=p.getNumOfTicket();
//amc++;
}
else if (p.getTicketType().equalsIgnoreCase("Business Class"))
{
abc+=p.getNumOfTicket();
//abc++;
}
p=(Passenger)passList.getNext();
}
int totalT=afc+amc+abc;
System.out.print("\n\n---------------------------------------------------------");
System.out.print("\n NUM OF TICKET/TYPE |");
System.out.print("\n---------------------------------------------------------");
System.out.print("\nFirst Class Passenger : " + afc);
System.out.print("\nMiddle Class Passenger : " + amc);
System.out.print("\nBusiness Class Passenger: " + abc);
System.out.print("\n---------------------------------------------------------");
System.out.print("\nTotal ticket sold>> " + totalT);

System.out.println("\n\nAfter delete : ");


String value = passList.deleteAnywhere();
p = (Passenger)passList.getFirst();
while(p != null)
{
String test1 = p.toString();
System.out.println(p.toString());
p = passList.getNext();
}

/** 1st process


/**count and display number of female and male passenger in each
ticket type**/
int cntffc=0,cntmfc=0,cntfmc=0,cntmmc=0,cntfbc=0,cntmbc=0;

17
p = (Passenger)passList.getFirst();
while (p!=null)
{
String newId = p.getKtmId().substring(4,5);
if (p.getTicketType().equalsIgnoreCase ("First Class"))
{
if (newId.equalsIgnoreCase ("F"))
{
cntffc++;
}
else
cntmfc++;
}
else if ((p.getTicketType().equalsIgnoreCase ("Middle Class")))
{
if (newId.equalsIgnoreCase ("F"))
{
cntfmc++;;
}
else
cntmmc++;
}
else if ((p.getTicketType().equalsIgnoreCase ("Business Class")))
{
if (newId.equalsIgnoreCase ("F"))
{
cntfbc++;
}
else
cntmbc++;
}

p = (Passenger)passList.getNext();
}
System.out.print("\n\n---------------------------------------------------------");
System.out.print("\n CURRENT PASSENGER COUNT
|");
System.out.print("\n---------------------------------------------------------");
System.out.print("\nFirst Class Passenger : Female " + "[" + cntffc + "]"
+ " Male" + "[" +cntmfc+ "]");
System.out.print("\nMiddle Class Passenger : Female " + "[" + cntfmc +
"]" + " Male" + "[" +cntmmc+ "]");
System.out.print("\nBusiness Class Passenger: Female " + "[" + cntfbc
+ "]" + " Male" + "[" +cntmbc+ "]");

18
/**2nd process
/**Determine passenger who pays highest price
* display passenger's name and KTM id
*/
Passenger hPass = null;
p = (Passenger)passList.getFirst();
double hPrice=0.00;
double highest=p.getTicketPrice()*p.getNumOfTicket();
while(p!=null)
{
if(p.getTicketPrice() > hPrice)
{
hPrice = p.getTicketPrice() * p.getNumOfTicket();
hPass = p;
}
p=(Passenger)passList.getNext();
}
System.out.println("\n\nHighest amount paid by: " + hPass.getPName()
+ "\nKTM ID : " + hPass.getKtmId());

/**Find and update ktm id by destination**/

System.out.println("\nSearch for passenger name>> ");


String sname = sc.next();
Passenger obj = null;
boolean found = false;
p=(Passenger)passList.getFirst();

while(p != null & !found)


{
if(p.getPName().equalsIgnoreCase(sname))
{
found = true;
}
else
{
p = (Passenger)passList.getNext();
}
}
if(found)
{
if(p.getPName().equalsIgnoreCase(sname))
{
System.out.print ("Enter new destination: ");
String sdest = sc.next();
p.setDestination(sdest);

19
}
//System.out.println("Updated KTM ID : " + getKtmId());
}
else
{
System.out.println("Not found");
}

System.out.print ("\n\n\t\t\t\t\t\t\t\t<< PASSENGER INFORMATION


SUMMARY >>");
/** 5th process
* Remove all Non-Citizen passenger from passList
* then store in new Linkedlist named nonList
*/

Linkedlist nonList = new Linkedlist();


//Linkedlist temp = new Linkedlist();
while(! passList.isEmpty())
{
p=(Passenger)passList.removeFromBack();
if (p.getPStatus().equalsIgnoreCase ("Non-Citizen"))
{
nonList.insertAtFront(p);
}
else
temp.insertAtFront(p);
}

while (! temp.isEmpty())
{
passList.insertAtFront(temp.removeFromBack());
}

p=(Passenger)nonList.getFirst();

System.out.println("\n\n--------------------------------------------------------------------------
----------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION NON_LIST
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS

20
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));

while (p!=null)
{
System.out.println (p.toString());
p=(Passenger)nonList.getNext();
}

System.out.println("-------------------------------------------------------------------------------
-------------------------------------------------------------------------------");

/** 6th process


* Remove all Citizen passenger from passList
* then store in new Linkedlist named citiList
*/

Linkedlist citiList = new Linkedlist();


Linkedlist hold = new Linkedlist();
while(! passList.isEmpty())
{
p=(Passenger)passList.removeFromBack();
if (p.getPStatus().equalsIgnoreCase ("Citizen"))
{
citiList.insertAtFront(p);
}
else
hold.insertAtFront(p);
}

while (! hold.isEmpty())
{
passList.insertAtFront(hold.removeFromBack());
}

p=(Passenger)citiList.getFirst();

System.out.println("\n\n--------------------------------------------------------------------------
----------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION CITI_LIST
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s

21
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));
while (p!=null)
{
System.out.println (p.toString());
p=(Passenger)citiList.getNext();
}

System.out.println("-------------------------------------------------------------------------------
-------------------------------------------------------------------------------");

////////

}
catch(FileNotFoundException fnfe)
{
System.out.println(fnfe.getMessage());
}
catch(IOException io)
{
System.out.println(io.getMessage());
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}

22
g) Class testKTMQ

import java.util.Scanner;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.StringTokenizer;

public class testKTMQ


{
public static void main (String[]args)
{
try
{
Scanner sc= new Scanner (System.in);
sc.useDelimiter("\n");

FileReader fr = new FileReader ("KTM.txt");


BufferedReader br = new BufferedReader(fr);

Queue ktmq = new Queue();


//Queue pq;

String dataKTM = null, name,status,id,ticketType,destination;


char category;
int tktNum=0;
double price=0.00;

while ((dataKTM = br.readLine()) !=null)


{
StringTokenizer st= new StringTokenizer (dataKTM, ";");

name=st.nextToken();
status=st.nextToken();
id=st.nextToken();
category=st.nextToken().charAt(0);
tktNum=Integer.parseInt(st.nextToken());
ticketType=st.nextToken();
price=Double.parseDouble(st.nextToken());
destination=st.nextToken();

Passenger pq = new Passenger


(name,status,id,category,tktNum,ticketType,price,destination);
ktmq.enqueue(pq);
}
br.close();

23
Queue temp = new Queue();
Queue alist = new Queue();
Passenger pq;

/**list passenger in queue*/

System.out.println("\n----------------------------------------------------------------------------
--------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION ");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));
while (!ktmq.isEmpty())
{
pq=(Passenger)ktmq.dequeue();
System.out.println(pq.toString());
temp.enqueue(pq);
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

/**remove passenger Kuala Lumpur from ktmq into klQ


* list of passenger going to Kuala Lumpur*/
Queue klQ = new Queue();
while(!ktmq.isEmpty())
{
pq = (Passenger)ktmq.dequeue();
if(pq.getDestination().equalsIgnoreCase("Kuala
Lumpur")||pq.getDestination().equalsIgnoreCase("KL Sentral"))
{
klQ.enqueue(pq);
}
temp.enqueue(pq);
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

24
System.out.println("\n----------------------------------------------------------------------------
--------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION(KUALA LUMPUR)
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));
while(!klQ.isEmpty())
{
pq = (Passenger)klQ.dequeue();
System.out.println(pq.toString());
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

/**
* update the price of each ticket of citizen to a new price by 5%
discount of the original price for new year promo
*/
while (!ktmq.isEmpty())
{
pq = (Passenger)ktmq.dequeue();
//pq.calcTotal();
temp.enqueue(pq);
}
while (!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

System.out.println("\n----------------------------------------------------------------------------
--------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION (NEW PRICE)
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

25
System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));
while(!ktmq.isEmpty())
{
pq = (Passenger)ktmq.dequeue();
System.out.println(pq.toString() + pq.calcTotal());
temp.enqueue(pq);
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

/**
* remove all passenger in Business Class and moved to a new queue
object called businessQ
*/
Queue businessQ = new Queue();
Queue middleQ = new Queue();
Queue firstQ = new Queue();
while(!ktmq.isEmpty())
{
pq = (Passenger)ktmq.dequeue();
if(pq.getTicketType().equalsIgnoreCase("Business Class"))
{
businessQ.enqueue(pq);
}
else if(pq.getTicketType().equalsIgnoreCase("Middle Class"))
{
middleQ.enqueue(pq);
}
else if(pq.getTicketType().equalsIgnoreCase("First Class"))
{
firstQ.enqueue(pq);
}
else
{
temp.enqueue(pq);
}
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());

26
}

System.out.println("\n----------------------------------------------------------------------------
--------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION (BUSINESS CLASS)
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");

System.out.println(String.format("%-15s%-32s%-15s%-20s%-20s%-20s%-15s
%-20s", "KTM ID", "NAME", "STATUS", "CATEGORY","TICKETS
BOOK","TICKET TYPE","PRICE/TICKET","DESTINATION"));
while(!businessQ.isEmpty())
{
pq = (Passenger)businessQ.dequeue();
System.out.println(pq.toString());
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

System.out.println("\n----------------------------------------------------------------------------
--------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION (MIDDLE CLASS)
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");
while(!middleQ.isEmpty())
{
pq = (Passenger)middleQ.dequeue();
System.out.println(pq.toString());
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

System.out.println("\n----------------------------------------------------------------------------
--------------------------------------------------------------------------------");
System.out.println("
PASSENGER INFORMATION (FIRST CLASS)

27
");

System.out.println("-------------------------------------------------------------------------------
-----------------------------------------------------------------------------");
while(!firstQ.isEmpty())
{
pq = (Passenger)firstQ.dequeue();
System.out.println(pq.toString());
}
while(!temp.isEmpty())
{
ktmq.enqueue(temp.dequeue());
}

catch(FileNotFoundException fnfe)
{
System.out.println(fnfe.getMessage());
}
catch(IOException io)
{
System.out.println(io.getMessage());
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}

28
SAMPLE INPUT

SAMPLE OUTPUT

– KTM –

29
>> SEARCH

30
>> UPDATE DESTINATION

31
– KTMQ –

32
33
CONCLUSION OF OUR FINDING

Our aim in this project is to create a system for the smoothness and
effectiveness for Keretapi Tanah Melayu Berhad(KTMB) to sort the
customers information in order easily.

The best data structure that was applied in this project would be to
remove all passengers to their own new queue object which means
Business Class to businessQ, Middle Class to middleQ and First Class to
firstQ. The reason this is the best data structure is because it is the longest
and kind of complicated to get it done. But, the results are satisfying. It is
important because it sorts the data according to these three types of class.
It is more effective to search and update destinations after they are sorted
out.

34
Name : 1) NURUL ELIZWANI BINTI KAMSANI Group Class : JCS1103B
2) ALIANAJWA MAISARAH BINTI MOHD AZAR
3) NURUL FAQIHAH BINTI ABDUL KARIM
ID : 1) 2021616054
2) 2021815376
3) 2021882416

35
Name : 1) NURUL ELIZWANI BINTI KAMSANI Group Class : JCS1103B
2) ALIANAJWA MAISARAH BINTI MOHD AZAR
3) NURUL FAQIHAH BINTI ABDUL KARIM
ID : 1) 2021616054
2) 2021815376
3) 2021882416

36
Name : 1) NURUL ELIZWANI BINTI KAMSANI Group Class : JCS1103B
2) ALIANAJWA MAISARAH BINTI MOHD AZAR
3) NURUL FAQIHAH BINTI ABDUL KARIM
ID : 1) 2021616054
2) 2021815376
3) 2021882416

37
Name : 1) NURUL ELIZWANI BINTI KAMSANI Group Class : JCS1103B
2) ALIANAJWA MAISARAH BINTI MOHD AZAR
3) NURUL FAQIHAH BINTI ABDUL KARIM
ID : 1) 2021616054
2) 2021815376
3) 2021882416

38

You might also like