Question

In: Computer Science

Bus ticket reservation project in java using class ,inheritance,interface

Bus ticket reservation project in java using class ,inheritance,interface

Solutions

Expert Solution

The following is the code for Ticket Reservation System in Java..

import java.util.Date;
public class reservation {
// Create an array of 20 seats, 14 window and 6 aisle.
private static int[] seats = new int[12];
public static void main(String args[]) {
System.out.println("Welcome to the KSTDC eservation system!");
System.out.println("Tourism, freebies, enjoyable destinations!");
System.out.println();
// Lets start by setting all seats equal to 0 (aka Empty)
for (int i = 0; i < 12; i++) {
seats[i] = 0;
}
// Setup our scanner and make the default the choice to window.
Scanner s = new Scanner(System.in);
int choice = 1;
// Ask user for a window or an aisle seat and store their coice.
System.out.print("Please enter 1 for window, 2 for aisle, 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 aisle seat for them instead.
if (seatnumber == -1) {
seatnumber = bookAisle();
if (seatnumber != -1) {
System.out.println("Sorry, we were not able to book a window seat. But do have an aisle seat.");
printBoardingPass(seatnumber);
}
}
else {
// Booking a window seat was successful.
System.out.println("You are ilucky 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 = bookAisle();

// 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 aisle seat. But do have a window seat.");
printBoardingPass(seatnumber);
}
}
else {
// Booking an aisle seat was successful.
System.out.println("You are in luck, we have an aisle 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 aisle seats were available.
if (seatnumber == -1) {
System.out.println("We are sorry, there are no window or aisle seats available.");
System.out.println();
}


Related Solutions

This is for a java program. Payroll System Using Inheritance and Polymorphism 1. Implement an interface...
This is for a java program. Payroll System Using Inheritance and Polymorphism 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY = 6000.00 STAFF_MONTHLY_HOURS_WORKED = 160 2. Implement an abstract class Employee with the following requirements: Attributes last name (String) first name (String) ID number (String) Sex - M or F Birth date - Use the Calendar Java class to create a date object Default argument constructor and argument constructors. Public methods toString - returning a string...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    *...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    * Gets the current number of entries in this set.    *    * @return The integer number of entries currently in the set.    */    public int getSize();    /**    * Sees whether this set is empty.    *    * @return True if the set is empty, or false if not.    */    public boolean isEmpty();    /**    *...
I want to write this program in java. Write a simple airline ticket reservation program in...
I want to write this program in java. Write a simple airline ticket reservation program in java.The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit...
Java I'm trying to create a program that replicates a theater ticket reservation system. I have...
Java I'm trying to create a program that replicates a theater ticket reservation system. I have a Seat class with members row(integer), seat(character) and ticketType(character). Where a ticket type can be 'A' adult, 'C' child, 'S' senior, or '.' recorded as empty. I have a Node generic class that points to other nodes(members): up, Down. Left, Right. It also has a generic payload. Lastly, I have an Auditorium class which is also generic. its member is a First Node<T>. As...
Add a generic Node class to the Java project. In the class Declare the fields using...
Add a generic Node class to the Java project. In the class Declare the fields using the generic type parameter, follow the book specification Define the accessor method getLink( ) Define the constructor, follow the book implementation Note: at the definition the name of the constructor is Node, however every time you use it as a type must postfix the generic type like Node<T> Define the addNodeAfter( ) method as explained in the PP presentation, use the generic type as...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
Consider an online reservation system for a bus company. The bus company includes several buses and...
Consider an online reservation system for a bus company. The bus company includes several buses and realizes trips to different cities. Each bus is identified by its plate number and a separately assigned bus number. The trips are based on a predefined schedule and stop at predefined bus stations. Each bus can have only one trip per day. Each bus includes a driver and one hostess. For long trips, the bus will have breaks at service and rest areas. There...
bus reservation system code using c language in this system we can add seat and remove....
bus reservation system code using c language in this system we can add seat and remove. this code will be in c language using 2 d aray
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with...
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with three int variables, indicating the arrivalTime, the timeForTheJob, and the priority. When the Job is created it is given the next sequential ID starting from 1. (You should use a static variable to keep track of where you are in ID assignment.) There are also int variables for startTime, waitTime (in queue) and endTime for the Job. The following methods are required: getID, set...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT