Академический Документы
Профессиональный Документы
Культура Документы
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.
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.
OUTPUT