Menu
Question Index
...


Write a program to book the seats in the given bus service. In the service, the number of rows, the seat pattern and the ticket price are given.

More Details:

1. If the seat pattern is 3-2 and the number of rows is 4, then the seat numbers will be
AAA AA
AAA AA
AAA AA
AAA AA
2. The ticket price is depending upon the row of the seat, for first row an additional 50 is charged and if it is the last row a discount of 50 is provided. For other rows the price will be as given in the service definition.
3. Every booked ticket should have the information about the seat number, price, whether window or not and the location of the seat.
4. While printing the availability if the seat is available you need to print A, if it is booked print B. A space should be printed to show the aisle (path).
5. If the seat pattern is 1-2 and the number of rows is 3, then the seat numbers will be
1 23
4 56
7 89

6. When booking the tickets we need to fill the top most left seat available. That is the seat with the smallest number should be booked first.
7. The seat location should be provided for every ticket. If the seat pattern is 4-1 and the number of rows is three and the allocated seat number is 8, then the seat location details should be
.... .
..X. .
.... .



For a service with seat pattern 3-2, with 4 rows and ticket price 300, the details will be as shown below.

Action/Status Availability/Result
Initial Availability AAA AA
AAA AA
AAA AA
AAA AA
If two tickets are booked, the ticket details are [1~350~W, 2~350~A]
Availability after booking two tickets BBA AA
AAA AA
AAA AA
AAA AA
If five more tickets are booked, the ticket details are [3~350~A, 4~350~A, 5~350~W, 6~300~W, 7~300~A]
Availability after booking five more tickets BBB BB
BBA AA
AAA AA
AAA AA

class SeatBooking

{    public static void main(String s[])
    {
        IService bangalore2030 = createService("BNG-2030", 4, "2-3", 300);
        System.out.println("##########################");
        System.out.print(bangalore2030.getAvailability());
        System.out.println("##########################");
        Double price = bangalore2030.bookSeats(2);
        System.out.println("Booking Cost For Two Tickets is : " + price);
        List tickets = bangalore2030.getLastBookedTickets();
        System.out.println("The details of two tickets are :");
        System.out.println("--------------------------------");
        printTickets(tickets);
        System.out.println("--------------------------------");
        System.out.println("##########################");
        System.out.print(bangalore2030.getAvailability());
        System.out.println("##########################");
        price = bangalore2030.bookSeats(10);
        System.out.println("Booking Cost For Ten Tickets is :  " + price);
        tickets = bangalore2030.getLastBookedTickets();
        System.out.println("The details of ten tickets are :");
        System.out.println("--------------------------------");
        printTickets(tickets);
        System.out.println("--------------------------------");
        System.out.println("##########################");
        System.out.print(bangalore2030.getAvailability());
        System.out.println("##########################");

    }


public static IService createService(String serviceName, int numberOfRows, String pattern, int ticketPrice) {
//Write code here to create the service.
}

public static void printTickets(List<ITicket> tickets) {
if (tickets != null) {
for (ITicket ticket : tickets) {
System.out.println(ticket);
System.out.println();
System.out.print(ticket.getLocation());
System.out.println();
}
}
}

//If required, write the additional methods here.
}
interface IService {

String getServiceName();

Double bookSeats(int numberOfSeats);

List<ITicket> getLastBookedTickets();

String getAvailability();
}

interface ITicket {

String getSeatNumber();

String getLocation();

int getPrice();

boolean isWindow();

String toString();
}

//Define the classes to implement the interfaces IService and ITicket. All the methods should be implemented as indicated by the method name.

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App