Question

In: Computer Science

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 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());
               }
           }
  

Solutions

Expert Solution

// 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.


Related Solutions

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...
Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. 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 on the number of flights. Create a linked list...
I am trying to create a function in JAVA that takes in an ArrayList and sorts...
I am trying to create a function in JAVA that takes in an ArrayList and sorts the values by their distance in miles in increasing order. So the closest (or lowest) value would be first. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. The code for the main class is not necessary. I am only really asking for the...
I am trying to create a method in JAVA that takes in an ArrayList and sorts...
I am trying to create a method in JAVA that takes in an ArrayList and sorts it by the requested "amenities" that a property has. So if someone wants a "pool" and "gym" it would show all members of the array that contain a "pool" and "gym". It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. You can edit it...
I am trying to create a makefile for the following program in Unix. The C++ program...
I am trying to create a makefile for the following program in Unix. The C++ program I am trying to run is presented here. I was wondering if you could help me create a makefile for the following C++ file in Unix and show screenshots of the process? I am doing this all in blue on putty and not in Ubuntu, so i don't have the luxury of viewing the files on my computer, or I don't know how to...
The source code I have is what i'm trying to fix for the assignment at the...
The source code I have is what i'm trying to fix for the assignment at the bottom. Source Code: #include <iostream> #include <cstdlib> #include <ctime> #include <iomanip> using namespace std; const int NUM_ROWS = 10; const int NUM_COLS = 10; // Setting values in a 10 by 10 array of random integers (1 - 100) // Pre: twoDArray has been declared with row and column size of NUM_COLS // Must have constant integer NUM_COLS declared // rowSize must be less...
I am trying to write a java program that determines if an inputted year is a...
I am trying to write a java program that determines if an inputted year is a leap year or not, but I am not able to use if else statements how would I do it. I don't need the code just advice.
I am trying to create a method in JAVA that takes in an ArrayList<Property> and filters...
I am trying to create a method in JAVA that takes in an ArrayList<Property> and filters it by the requested price range that a property has. So if someone wants a property between the value of 10(min) and 20(max) it would show all members of the array that meet those conditions.. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below....
I am trying to create a method in JAVA that takes in an ArrayList<Property> and sorts...
I am trying to create a method in JAVA that takes in an ArrayList<Property> and sorts it by the amount of "reviews" that a property has in increasing order. So the most reviews first. So each listing in the array would contain a different number of reviews, and they should be sorted based on that value. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to...
*****IN JAVA**** Implement a theater seating chart  as a two-dimensional array of ticket prices, like this: {10,...
*****IN JAVA**** Implement a theater seating chart  as a two-dimensional array of ticket prices, like this: {10, 10, 10, 10, 10, 10, 10, 10, 10, 10} {10, 10, 10, 10, 10, 10, 10, 10, 10, 10} {10, 10, 10, 10, 10, 10, 10, 10, 10, 10} {10, 10, 20, 20, 20, 20, 20, 20, 10, 10} {10, 10, 20, 20, 20, 20, 20, 20, 10, 10} {10, 10, 20, 20, 20, 20, 20, 20, 10, 10} {20, 20, 30, 30, 40,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT