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...
An online air ticket reservation company is experimenting with a new interactive user interface design for...
An online air ticket reservation company is experimenting with a new interactive user interface design for its customers. Study any leading online air ticket reservation system to understand this interface and using it, give examples of any three social impact of interface design for following elements. You can use screenshots to elaborate your example. Describe the new system and its benefits Outline the development process
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...
write Java program has two classes ,( using Inheritance ) first class set ( id ,...
write Java program has two classes ,( using Inheritance ) first class set ( id , name ) and method output second class ( id , name , Mark 1 , Mark 2 , Mark 3 ) method total , average , grade , results ( if the student pass or not ) , and output method
4) Define an abstract class Name Java class that implements interface Comparable   
4) Define an abstract class Name Java class that implements interface Comparable   
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...
JAVA code Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface...
JAVA code Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface below for details. EditableDigraph below: import java.util.NoSuchElementException; /** * Implements an editable graph with sparse vertex support. * * */ public interface EditableDiGraph {    /** * Adds an edge between two vertices, v and w. If vertices do not exist, * adds them first. * * @param v source vertex * @param w destination vertex */ void addEdge(int v, int 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT