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...
Java homework problem. This is my hotel reservation system. I'm trying to add a few things...
Java homework problem. This is my hotel reservation system. I'm trying to add a few things to it. You will be changing your Hotel Reservation system to allow a user to serve more rooms and the rooms will be created as objects. For this project you will be modifying the Hotel Reservation system to allow a user to serve more rooms and the rooms will be created as objects. You will be create a Room object that will allow the...
Android Studio (Java) I'm trying to create a simple calculator. I want to put out a...
Android Studio (Java) I'm trying to create a simple calculator. I want to put out a message if they try to divide by 0. I have this so far. What code should I put? divide.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (number1.getText().length() != 0 && number2.getText().length() != 0) { double n1= Double.parseDouble(number1.getText().toString()); double n2= Double.parseDouble(number2.getText().toString()); double res= n1 / n2; result.setText(String.valueOf(res)); } else { Toast.makeText(view.getContext(), "Please enter the numbers properly", Toast.LENGTH_SHORT).show(); } } });
Description: The purpose of the program is to create a Java ticket purchasing program that allows...
Description: The purpose of the program is to create a Java ticket purchasing program that allows for users to log in, purchase tickets, keep records of tickets purchased, and keep information about the user. Program Requirements: The following are the program requirements: Must be fully functioning including registration, log-in, view events, and purchase tickets Tickets should be purchased using “points”, no information should be provided via the user for payment method. Default each user to an allotted number of points...
Bus ticket reservation project in java using class ,inheritance,interface
Bus ticket reservation project in java using class ,inheritance,interface
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...
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'm trying to write a feet to meters and centimeters program and I'm looking for a...
I'm trying to write a feet to meters and centimeters program and I'm looking for a little help so I can see how close I got. It should do the following: Write a convertToMetric class that has the following field: standard - holds a double, standard length value in feet. The class should have the following methods: Constructor - that accepts a length in feet (as a double) and stores it in the standard field. setStandard - accepts a standard...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT