Вы находитесь на странице: 1из 5

Abstract of the Project Bus Ticket System

The purpose of Bus Ticket Boking System is to automate the existing manual system by
the help of computerized equipments and full-fledged computer software, fulfilling
their requirements,so that their valuable data/information can be stored for a long
period with easily availiable and easy to work with.
The aim is to automate its existing manual system by the help of computerized
equipments

import java.util.Scanner;
import java.util.Date;
public class new1 {
// Create an array of 12 seats, 6 window and 6 aside.

private static int[] seats = new int[12];


public static void main(String args[]) {

System.out.println("Welcome to national bus reservation system!");


System.out.println("Have a fabulous ride!");
System.out.println();
// Lets start by setting all seats equal to 0 (Empty)
for (int i = 0; i < 12; i++) {
seats[i] = 0;
}
// Setup our scanner and default the choice to window.
Scanner s = new Scanner(System.in);
int choice = 1;
// Ask user for a window or an Aside seat and store their coice.
System.out.print("Please enter 1 for window, 2 for aside, or 0 to exit: ");
choice = s.nextInt();
// While their choice is not the one for exit, execute our booking.

while (choice != 0) {
int seatnumber = 0;
// If they chose a window seat, attempt to book it.
if (choice == 1) {
seatnumber = bookWindow();
// No window seats available, try booking an aside seat for them
instead.
if (seatnumber == -1) {
seatnumber = bookAside();
if (seatnumber != -1) {
System.out.println("Sorry, we were not able to book a window
seat. But do have an aside seat.");
printBoardingPass(seatnumber);
}
}
else {
// Booking a window seat was successful.
System.out.println("You are in luck, we have a window seat
available!");
printBoardingPass(seatnumber);
}
}
else if (choice == 2) {
// If they chose booking an isle, check to see if it is available.
seatnumber = bookAside();
// If not available, see if we have window seats available.
if (seatnumber == -1) {
seatnumber = bookWindow();
if (seatnumber != -1) {
System.out.println("Sorry, we were not able to book an aside
seat. But do have a window seat.");
printBoardingPass(seatnumber);
}
}
else {
// Booking an Aside seat was successful.
System.out.println("You are in luck, we have an aside seat
available!");
printBoardingPass(seatnumber);
}
}
else {
// Print an error message if they did not choose 1, 2, or 0 for their
choice.
System.out.println("Invalid choice made. Please try again!");
choice = 0;
}
// No window or Aside seats were available.
if (seatnumber == -1) {
System.out.println("We are sorry, there are no window or aside seats
available.");
System.out.println();
}
// Reprompt for a choice
System.out.print("Please enter 1 for window, 2 for aside, or 0 to exit:
");
choice = s.nextInt();
}
}
// This function checks for window seats and returns seat number or -1 if full.
private static int bookWindow() {
for (int i = 0; i < 6; i++) {
if (seats[i] == 0) {
seats[i] = 1;
return i + 1;
}
}
return -1;
}
// This function checks to see if Aside seats were available, -1 if full.

private static int bookAside() {


for (int i = 6; i < 12; i++) {
if (seats[i] == 0) {
seats[i] = 1;
return i + 1;
}
}
return -1;
}
// This simply prints out a nice little boarding pass message with their seat
number and date of issue.
private static void printBoardingPass(int seatnumber) {
Date timenow = new Date();
System.out.println();
System.out.println("Date: " + timenow.toString());
if(seatnumber<=6)
System.out.println("Boarding pass for window seat number: " + seatnumber);
if(seatnumber>6&&seatnumber<=12)
System.out.println("Boarding pass for aside seat number: " + seatnumber);
System.out.println("This ticket is non-refundable and non-transferable.");
System.out.println("Please be curteous, do not smoke. Enjoy your trip.");
System.out.println();
}
}

OUTPUT

Welcome to national bus reservation system!


Have a fabulous ride!

Please enter 1 for window, 2 for aside, or 0 to exit: 1


You are in luck, we have a window seat available!

Date: Sun Apr 08 23:01:24 IST 2018


Boarding pass for window seat number: 1
This ticket is non-refundable and non-transferable.
Please be curteous, do not smoke. Enjoy your trip.
Please enter 1 for window, 2 for aside, or 0 to exit: 1
You are in luck, we have a window seat available!

Date: Sun Apr 08 23:01:26 IST 2018


Boarding pass for window seat number: 2
This ticket is non-refundable and non-transferable.
Please be curteous, do not smoke. Enjoy your trip.

Please enter 1 for window, 2 for aside, or 0 to exit: 2


You are in luck, we have an aside seat available!

Date: Sun Apr 08 23:01:28 IST 2018


Boarding pass for aside seat number: 7
This ticket is non-refundable and non-transferable.
Please be curteous, do not smoke. Enjoy your trip.

Please enter 1 for window, 2 for aside, or 0 to exit: 2


You are in luck, we have an aside seat available!

Date: Sun Apr 08 23:01:29 IST 2018


Boarding pass for aside seat number: 8
This ticket is non-refundable and non-transferable.
Please be curteous, do not smoke. Enjoy your trip.

Please enter 1 for window, 2 for aside, or 0 to exit: 0

Вам также может понравиться