In: Computer Science
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 you can see, its a linked list of nodes where each node is supposed to be a seat (Node<Seat>). The Auditorium is supposed to be a grid of Seat Nodes that contain the seat information within. This way, I can later use the information to intake customer orders and check availability, recommend a best option if not available, etc.
My problem is I'm having trouble creating an overloaded constructor for the Auditorium class. The current auditorium seating information is held in a text file with text such as:
AA.AA....AAA..AACCSS
..AC.....A.........A
S...........AACCCAAC
.AA...CC.SS.....SSC.
A.A..S...S..A......A
I need to add each seat into a node into the auditorium grid before asking the customer for their order to know seat availability.
I tried creating this LONG constructor, but I think the issue is converting the item of type Seat into an item or generic T ((T)currentSeat). This causes the auditorium to output A as ticket type for EVERY single seat in the auditorium. Could you give advice on how to better create an auditorium through the constructor?
for(int i = 0 ; i < rows ;
i++)
{
//System.out.println("row " + i);
currentRowFromFile = readFile.nextLine();
for (int j = 0;
j < columns; j++)
{
//System.out.println( "column " + j);
currentSeat.setRow(i);
currentSeat.setSeat((char)('A'+ j));
//System.out.print("seat column ");
//System.out.println((char)('A'+ j));
currentSeat.setTicketType(currentRowFromFile.charAt(j));
if(j == 0 && i == 0)
{
First = new Node<T>
((T)currentSeat);
lastNodeCreated =
First;
thisRowsFirstElement =
First;
System.out.println("The node
being added for index " + i + " " + j + "has seat type: " +
currentSeat.getTicketType());
}
if(j == 0 && i!= 0) // new row first
element
{
//first column on a different
row
Node<T>newNodeToInsert
= new Node<T>((T)currentSeat);
thisRowsFirstElement.setDown(newNodeToInsert); //move
down
thisRowsFirstElement.getDown().setUp(thisRowsFirstElement);
thisRowsFirstElement =
thisRowsFirstElement.getDown(); // now continue on this row
lastNodeCreated =
thisRowsFirstElement;
System.out.println("The node
being added for index " + i + " " + j + "has seat type: " +
currentSeat.getTicketType());
}
else if(i == 0 && j != 0) // top
row
{
Node<T> newNodeToInsert
= new Node<T>((T)currentSeat);
lastNodeCreated.setRight(newNodeToInsert);
lastNodeCreated.getRight().setLeft(lastNodeCreated); //
<-->
lastNodeCreated =
lastNodeCreated.getRight();
System.out.println("The node
being added for index " + i + " " + j + "has seat type: " +
currentSeat.getTicketType());
}
else if(i != 0 && j != 0) // not top row
or first column
{
Node <T>
newNodeToInsert = new Node<T> ((T)currentSeat);
lastNodeCreated.setRight(newNodeToInsert);
lastNodeCreated.getRight().setLeft(lastNodeCreated);
lastNodeCreated.getRight().setUp(lastNodeCreated.getUp().getRight());
lastNodeCreated.getUp().getRight().setDown(lastNodeCreated.getRight());
lastNodeCreated =
lastNodeCreated.getRight();
System.out.println("The node
being added for index " + i + " " + j + "has seat type: " +
currentSeat.getTicketType());
}
}
// booking system.
Enums :
public enum SeatStatus {
SEAT_BOOKED,
SEAT_NOT_BOOKED;
}
public enum MovieStatus {
Movie_Available,
Movie_NotAvailable;
}
public enum MovieType {
ENGLISH,
HINDI;
}
public enum SeatType {
NORMAL,
EXECUTIVE,
PREMIUM,
VIP;
}
public enum PaymentStatus {
PAID,
UNPAID;
}
class User {
int userId;
String name;
Date dateOfBirth;
String mobNo;
String emailId;
String sex;
}
class Movie {
int movieId;
int theaterId;
MovieType movieType;
MovieStatus movieStatus;
}
class Theater {
int theaterId;
String theaterName;
Adress adress;
List<Movie> movies;
float rating;
}
class Booking {
int bookingId;
int userId;
int movieId;
List<Movie> bookedSeats;
int amount;
PaymentStatus status_of_payment;
Date booked_date;
Time movie_timing;
}
class Address {
String city;
String pinCode;
String state;
String streetNo;
String landmark;
}
The above code has classes and attributes only. In the above code,
as you can see enums are self-explanatory.
We have users class in which users details are kept.
Theater class in which name of the theater, it’s address and list
of movies currently running are kept.
Booking class lets you book the seat in a particular theater. It
keeps a reference in Movie, Payment class.