0% found this document useful (0 votes)
140 views

Assignment 1 - de Chan

The document describes an assignment to implement a train booking system using linked lists in Java. Students must create three linked lists to store train, customer, and booking data. The program displays a menu allowing users to load and manipulate data in the lists, including adding, searching, sorting, and deleting elements. Students must submit their source code, input files, and a batch file to run the program compressed in a zip folder named after their class, name, and student ID.

Uploaded by

Luat Minh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views

Assignment 1 - de Chan

The document describes an assignment to implement a train booking system using linked lists in Java. Students must create three linked lists to store train, customer, and booking data. The program displays a menu allowing users to load and manipulate data in the lists, including adding, searching, sorting, and deleting elements. Students must submit their source code, input files, and a batch file to run the program compressed in a zip folder named after their class, name, and student ID.

Uploaded by

Luat Minh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DSA - Assignment 1

Train Booking System


using linked list data structure
INTRODUCTION

Your first assignment in this block will be using linked list data struture for implementing a
Train Booking System (TBS) in Java language.
TBS manages information about Traines, customers and train booking. These information are:

About a train:
1. tcode (string): the code of the train (this should be unique for the train).
2. train_name (string): the name of the train.
3. seat (integer): the number of seats in the train (seat > 0).
4. booked (integer): the number of booked seats in the train (booked >= 0 and booked ≤
seat).
5. depart_time (double): The depature time of the train (depart_time >= 0).
6. depart_place (string): The place of departure of the train.

About a customer:
1. ccode (string): the code of the customer (this should be unique for the customer).
2. cus_name (string): the name of the customer.
3. phone (string): The phone number of the customer (must contain digits only).

About Booking:
1. tcode (string): the code of the train to be booked.
2. ccode (string): the code of the customer.
3. seat (integer): the number of seats to be booked on the train.

YOUR TASKS

You should use 3 linked lists, each one is used to store data for trains, customers or train booking
items. You should create linked lists from scratch, do not use list structures available in java like
ArrayList, Vector or LinkedList classes.
On running, your program displays the menu as below:

Train list (8 marks):


1.1. Load data from file
1.2. Input & add to the head
1.3. Display data
1.4. Save train list to file
1.5. Search by tcode
1.6. Delete by tcode
1.7. Sort by tcode
1.8. Add after position k
1.9. Delete the node before the node having tcode = xCode

Customer list (1 mark):


2.1. Load data from file
2.2. Input & add to the end
2.3. Display data
2.4. Save customer list to file
2.5. Search by ccode
2.6. Delete by ccode

Booking list (1 mark):


3.1. Input data
3.2. Display data width available seats
3.3. Sort by tcode + ccode

TASKS EXPLANATION

Train list (8 marks):


1.1. Load data from file
Allow a user to input the file name that contains information of trains. The content of the text
file may be

B03 | Sug | 12 | 3 | 11 | PA
B01 | Mil | 10 | 5 | 5.7 | PC
B02 | App | 5 | 2 | 4 | PB
B05 | Roo | 7 | 6 | 15 | PE
B07 | Bee | 11 | 3 | 12 | PF
B04 | Boo | 9 | 5 | 5 | PD

The first line means that: tcode = B03, train_name = Sug, seat = 12, booked = 3, depart_time =
11 and depart_place = PA.
The task of this option is to read rows from the text file and add to the end of the list. If the list
is not empty, then the program asks the user if he/she wants to keep the existing data or not.

1.2. Input & add to the head


Allow a user to add new information about a train. After checking validation of data (including
that the tcode could not be duplicated), the train is added to the head of the list.

1.3. Display data


Display data in format:
tcode | train_name | seat | booked | depart_time | depart_place | available_seat
where available_seat = seat - booked
For example after loading the above file, this option give the output below:
tcode|Train_name|Seat|booked|depart_time|depart_place|available_
seat
----------------------------------------------------------------
---
B03 | Sug | 12 | 3 | 11 | PA | 9
B01 | Mil | 10 | 5 | 5.7 | PC | 5
B02 | App | 5 | 2 | 4 | PB | 3
B05 | Roo | 7 | 6 | 15 | PE | 1
B07 | Bee | 11 | 3 | 12 | PF | 8
B04 | Boo | 9 | 5 | 5 | PD | 4

1.4. Save train list to file


Allow a user to input the file name and save the train list to the file. The information and format
like the option 1.3.

1.5. Search by tcode


Write the function:
Node search(String xCode) {}
which return reference to the node whose info contains the train with tcode = xCode.
Allow a user to input the tcode to be searched and display the result: found or not found.

1.6. Delete by tcode


Write the function:
void dele(String xCode) {}
which deletes the node whose info contains the train with tcode = xCode.
Allow a user to input the tcode to be deleted and then delete the train having that tcode.

1.7. Sort by tcode

1.8. Add after position k


The position of the first element is 0, the second's is 1
Allow a user to input data for a train and add the train after position k.

1.9. Delete the node before the node having tcode = xCode
Allow a user to input xCode and delete the node before the node having tcode = xCode.

Customer list (1 mark):


2.1. Load data from file
Allow a user to input the file name that contains information of customers. The content of the
file may be

C03 | Hoa | 1902


C01 | La | 1901
C02 | Canh | 1903
C05 | Cay | 1910
The first line means that: ccode = C03, name = Hoa, phone = 1902

2.2. Input & add to the end


2.3. Display data
2.4. Save customer list to file
2.5. Search by ccode
2.6. Delete by ccode

Booking list (1 mark):


3.1. Input data
Allow a user to input booking item.
When running, the screen looks like:
Enter train code:
Enter customer code:
Enter number of seats to be booked:
After the user enter tcode and ccode, the program check and acts as follows:
- If tcode not found in the Train list or ccode not found in the customer list then data is not
accepted.
- If both tcode and ccode are found in the booking list then data is not accepted.
- If tcode and ccode found in Traines and customers lists but booked = seat then inform the user
that the train is exhausted.
- If tcode or ccode found and in the Train list booked < seat and k is the entered seat then if k <=
seat - booked then data is accepted and added to the end of the Booking list.

3.2. Display booking data


3.3. Sort by tcode + ccode

Submission Requirements
Create the directory with a name like <class>-<name><roll number>-ASS1, e.g.
SE0508-QuangTV00456-AS1 (1)
The (1) directory contains the following files:
1. The run.bat file to run your program.
2. Your source code files.
3. train.txt and customer.txt files.
The statements in run.bat file may be:
cls
javac Main.java
java Main
pause
del *.class
Compress the folder (1) to .zip (or .rar) file (with the same name) and upload to cms.
Assignment assessment
You will be asked to modify immediately and to explain your assignment in class room to be
sure that you are really the author of the assignment you submitted.

You might also like