Java
Java
On
Submitted by,
2023-24
1
Annexure – I A
PART A
Micro-Project Proposal
4th Semester
Development Bus Reservation System Using Java
There are two parts of the system, one as an admin and the other as user. To use the
system as admin you have to log in to the system. Enter the admin id and password to
get access to the system. Talking about the user perspective, the user can simply book
the ticket. He/she should first choose the destination they want to travel. Once they
select the destination, thereafter, they can select the type of bus service they and also
the route through they want to travel. After selecting all they can head towards the
confirmation of the ticket.
Bus Reservation and Ticketing System is a simple console based application in Java.
The feature of this simple application includes adding passengers record, billing and
viewing total records. In order to add a passenger, the user has to provide passenger’s
name, destination, number of passengers and discount number. Other features include
viewing available destination records, billings. This whole system is not built with the
help of Netbeans IDE.
There’s no external database connectivity in this simple project. For billings, he/she
has to enter passenger’s name. Then the system displays all the informations of the
passenger such as name, destination, fare price, number of passengers and discount
amount. It also shows the total fare amount and the user has to provide the amount to
pay. To view records, the user can simply provide passenger’s name which will
display each and every information including total fare price with paid amount,
change and status.
2
2.0 Aim of the Micro-Project
3
PART B Annexure – IIA
Every time an object is created using the new() keyword, at least one constructor is called.
4
2.0 Aim of Micro Project
1) To develop programming skills
2) To Understand Logic of the Program.
Increase The Ticket Booking efficiency
1. Create a Bus class with attributes like bus Number, source, destination, total Seats, and
available Seats.
2. Create a Reservation class with attributes like passenger Name, passenger Age,
passenger Gender, bus Number, and seat Number.
3. Create a main class Bus Reservation System to handle the user interface and user
input/output.
4. In the main class, create an array of Bus objects to store information about different
buses.
5. display all the buses When a user reserves a seat, the available Seats attribute of that
bus should be decremented, and when a user cancels a seat, the available Seats attribute
should be incremented.
6. Display all the passengers or search for a particular passenger.
7. Save all the data in a file so that it can be accessed even after the program is closed.
Program:
5
import java.io.*;
String user,password,yn,search,again,choice;
int to=0,y=1,z=0,end=0,r=1;
try{
for(int i=1;i<4;){
user = in.readLine();
password = in.readLine();
available[o]=20;
System.out.println("********************************************");
System.out.println("********************************************");
6
System.out.println("***************************************");
System.out.println("***************************************\n");
for(x=1; x==1;){
choice=in.readLine();
if (choice.equals("1")){
System.out.println("***************************************");
System.out.println("***************************************");
System.out.println("***************************************");
System.out.println("***************************************\n");
x=0;
else if (choice.equals("2")){
int print=1;
System.out.println("***************************************");
System.out.println("***************************************");
7
System.out.println("***************************************");
System.out.println("***************************************\n");
if((available[1]==0)&&(available[2]==0)&&(available[3]==0)&&(available[4]==0)&&(available[5]
==0)){
x=0;
}else{
for(x=1; x==1;){
ticketS[z][0] = in.readLine();
x=0;
if(ticketS[l][0].equalsIgnoreCase(ticketS[z][0])){
x=1;
for(x=1; x==1;){
to = Integer.parseInt(in.readLine());
if(to<1 || to>5){
System.out.println("Invalid Input!");
x=1;
if(to==d){
if(available[to]==0){
x=1;
8
}
x=0;
String dest[] = { " ", "DAVAO CITY", "BUTUAN CITY", "CABADBARAN", "TANDAG",
"CAGAYAN"};
ticketS[z][1] = dest[to];
ticketD[z][0] = fare[to];
for(x=1; x==1;){
ticketI[z][0] = Integer.parseInt(in.readLine());
if(to==p){
print=1;
available[to] = available[to]-ticketI[z][0];
//add the inputed number to the subtracted seat, to back the original seat//
if(available[to]<0){
System.out.print("Sorry, We don't have seat available for " +ticketI[z][0] +" person\n");
available[to] = available[to]+ticketI[z][0];
x=1;
print=0;
else{
x=0;
9
}
}}
for(x=1;x==1;){
ticketI[z][1] = Integer.parseInt(in.readLine());
if(ticketI[z][1]>ticketI[z][0]){
System.out.println("Invalid Input!");
x=1;
else{
break;
if(print==1){
System.out.println("\n***************************************");
System.out.println("***************************************");
System.out.println("***************************************");
System.out.println("***************************************\n");
ticketS[z][2]="0";
double discount=(ticketD[z][0]-(ticketD[z][0]*0.2))*ticketI[z][1];
ticketD[z][2]= ((ticketI[z][0]-ticketI[z][1])*ticketD[z][0])+discount;
10
x=0;
z++;
else if (choice.equals("3")){
for(x=1; x==1;){
search = in.readLine();
int s=1;
for(int b=0;b<z;b++){
if(search.equalsIgnoreCase(ticketS[b][0])){
System.out.println("***************************************");
System.out.println("***************************************");
System.out.println("***************************************");
System.out.println("***************************************");
s=0;
x=0;
if(ticketS[b][2].equals("x")){
x=0;
else{
ticketS[b][2]="x";
for(x=1; x==1;){
11
System.out.println("\nPASSENGER'S TOTAL FARE: Php "+ticketD[b][2]);
pay[b] = Double.parseDouble(in.readLine());
change[b]=pay[b]-ticketD[b][2];
if(change[b]<0){
System.out.println("Invalid Input!");
x=1;
else{
System.out.println("");
x=0;
if (s==1){
again=in.readLine();
if(again.equalsIgnoreCase("y")){
q=0;
else if (again.equalsIgnoreCase("n")){
q=0;
x=0;
else{
System.out.println("\nInvalid input!\n");
12
}
else if (choice.equals("4")){
search = in.readLine();
int s=1;
if(search.equalsIgnoreCase(ticketS[x][0])){
System.out.println("***************************************");
System.out.println("***************************************");
if(ticketS[x][2].equals("x")){
System.out.println("STATUS: PAID");
else{
System.out.println("***************************************");
System.out.println("***************************************");
13
s=0;
sx=4;
if (s==1){
sx++;
else if(choice.equals("5")){
end=1;
x=0;
System.out.println("Thank You!");
else{
System.out.println("Invalid Input!");
x=1;
for(y=1; y==1;){
if(end==1){
break;
yn = in.readLine();
if (yn.equalsIgnoreCase("y")){
x=1;
y=0;
14
else if (yn.equalsIgnoreCase("n")){
System.out.println("\nThank You!!!");
break;
else{
System.out.println("Invalid Input!!!");
y=1;
i=4;
else{
i++;
Catch (execption e)
15
5.0 Actual Resources Used
16
17
7.0 Skill Developed / learning out of this Micro-Project
****************
18