Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your assignment is to design a TicketManager class that can keep track of the nu

ID: 3691827 • Letter: Y

Question

Your assignment is to design a TicketManager class that can keep track of the number of seats available in a theater’s auditorium. The TicketManager class should have a two-Dimensional array, which has 15 rows and 30 columns for all the seats available in the auditorium, also an array of double to keep track of the price of tickets for each row. Each row has a different price. Use the following UML diagram to design the class:

--------------------------------------------------------------------

+ NUMROWS : static final int = 15

+NUMCOLUMNS : static final int = 30

-seats[NUMROWS][NUMCOLUMNS] : char

-price[NUMROWS]: double

-int : seatsSold

-double : totalRevenue

==========================

+TicketManager()

+requestTickets(int, int, int): bool

+purchaseTickets(int, int, int) : bool

+getTotalRevenu(): double

+ getSeatsSold() : int

+ getPrice(int) : double

+ getSeat (int, int) : char

+ printTickets(int, int, int): void

-------------------------------------------------------------

You will need to create two files – TicketManager.java file, and Assignment8.java file which has the main method.

• Your program should read from two files, seatAvailability.txt and seatPrices.txt (they need to be downloaded from the course website.) If your folder is named “Assignment8”, then they need to be placed within the folder “Assignment8”. You can write click and save the files.

• The size of the 2-D arrays will be decided by NUMROWS and NUMCOLUMNS. In your class, you declare it as: public class TicketManager { public static const int NUMROWS = 15; public static const int NUMCOLUMNS = 30; ………..…… }

Sample Runs:

Sample runs:

User input is represented by bold

ASU Gammage Theater

1. View Available Seats

2. Request Tickets

3. Display Theater Sales Report

4. Exit the Program

1

Seats 123456789012345678901234567890

Row 1 ##############################

Row 2 ##############################

Row 3 ##############################

Row 4 ##############################

Row 5 ##############################

Row 6 ##############################

Row 7 ##############################

Row 8 ##############################

Row 9 ##############################

Row 10 ##############################

Row 11 ##############################

Row 12 ##############################

Row 13 ##############################

Row 14 ##############################

Row 15 ##############################

Legend:

* = Sold

# = Available

ASU Gammage Theater

1. View Available Seats

2. Request Tickets

3. Display Theater Sales Report

4. Exit the Program

2

Number of seats desired (1 - 30): 3

Desired row (1-15): 1

Desired starting seat number in the row (1 - 30): 1

The seats you have requested are available for purchase.

The total purchase price is 3 X $12.50 = $37.50

Do you wish to purchase these tickets (Y/N)? y

Num Seats: 3

The price for the requested tickets is $ 37.50

Please input amount paid: $4

0 ***********************************************

* Gammage Theater *

* Row 1 Seat 1 *

* Price: $ 12.50 *

*********************************************** ***********************************************

*Gammage Theater *

* Row 1 Seat 2 *

* Price: $ 12.50 *

*********************************************** ***********************************************

* Gammage Theater *

* Row 1 Seat 3 *

* Price: $ 12.50 * ***********************************************

Tickets purchased: 3

Payment : $ 40.00

Total ticket price: $ 37.50

Change due : $ 2.50

Explanation / Answer

1. seatAvailability.txt

##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################
##############################

*******************************************************************************************

2. seatPrices.txt

12.50
12.50
12.50
12.50
10.00
10.00
10.00
10.00
8.00
8.00
8.00
8.00
5.00
5.00
5.00

*******************************************************************************************

3. TicketManager.java

import java.io.*;
import java.util.*;

public class TicketManager
{
   // instance Variables:
   // the size of 2D arrays determined by the following variables, rows and columns respectively
   public static final int NUMROWS = 15; // Do not use const, it is final in Java...
   public static final int NUMCOLUMNS = 30;
   //2-D array to keep track of seats.
   private char[][] seats = new char[NUMROWS][NUMCOLUMNS];
   // 1-d array to keep track of price.
   private double[] price = new double[NUMROWS];
   // int to keep track of seats sold
   private int seatsSold = 0;
   // double to keep track of total revenue
   private double totalRevenue = 0.0;
  
   // Constructor
   // TicketManager makes the array seats the from reading the file seatinability.txt
   public TicketManager()
   {
       try
       {
           //make a new scanner object that will read from the file
           Scanner avail = new Scanner(new File("seatAvailability.txt"));
String line;
int col = 0, row = 0;
while(avail.hasNext())
{
   line = avail.next();
for(col = 0; col < line.length() && col < NUMCOLUMNS; col++)
{
seats[row][col] = line.charAt(col);
}
row++;
}

           // closes avail scanner.
           avail.close();
          
           // Repeat above for price array, only one for loop caz its 1-d
           Scanner priceTxt = new Scanner(new File("seatPrices.txt"));
           while(priceTxt.hasNext())
           {
               for (int i = 0; i < NUMROWS; i++)
               {
                       double temp1 = priceTxt.nextDouble();
                       price[i] = temp1;
               }
           }
           // close scanner
           priceTxt.close();
       }
       catch (FileNotFoundException e)
       {
           System.err.println("error: "+e.getMessage());
       }
   }
  
   // requestTickets method
   public boolean requestTickets(int numTickets, int desiredRow, int desiredSeatStart)
   {
       // for loop to control what columns it checks, i which equals their desired column start.
       // Then goes untilit checks the amounr of tickets they want by using j - numTickets.
       for (int i = desiredSeatStart; i < NUMROWS - numTickets; i++)
       {
           // if the seat is taken (*) then say u cant use it, false.
           if (seats[desiredRow][i] == '*')
               return false;
       }
       return true;
   }
  
   // method purchaseTickets changes the seats array and updates seatsSold and totalRevenue
   // i dont get why it is a boolean, it just updates stuff doesn't return a true/false,
   // returning that can be done in main (i.e. if Y, then CLASS.purchaseTickets(....) not this way).
   public void purchaseTickets(int numTickets, int desiredRow, int desiredSeatStart)
   {
       // need to change the seats in the 2-d array from # to *.
       // use same loop, as requestTickets, but instead of if statement, change the char.
       for (int i = desiredSeatStart; i < NUMROWS - numTickets; i++)
       {
           // change seat from available, #, to taken, *.
           seats[desiredRow][i] = '*';              
       }
       //update seats sold:
       seatsSold += numTickets;
      
       // update revenue (desired row also equals the price from the array times the num of seats sold.
       totalRevenue += (price[desiredRow]*numTickets);
   }
  
   // method getTotalRevenue() will return total revenue
   public double getTotalRevenue()
   {
       return totalRevenue;
   }
  
   // method to return the number of seats sold
   public int getSeatsSold()
   {
       return seatsSold;
   }
  
   // method to get price of current row
   public double getPrice(int row)
   {
       // from entered row, access double row's price associated with that row
       double priceOfRow = price[row];      
       // return it.
       return priceOfRow;
   }
  
   // method not very clear, assuming it is returning a # or *.
   public char getSeat(int row, int column)
   {
       char seatOfSelected = seats[row][column];
       return seatOfSelected;
   }
  
   // method to print the tickets purchased.
   public void printTickets(int numSeats, int row, int column)
   {
       // go through seat by seat and print out each ticket using for loop
       for (int i = column; i < NUMROWS - numSeats; i++)
       {
           System.out.println("***********************************************");
           System.out.println("* Gammage Theater*");
           System.out.println("* Row " + row + " Seat " + i + " *");
           System.out.println("* Price: $ " + price[row] + " *");
           System.out.println("***********************************************");
       }
   }
  
   // method displaySeats displays the content of the 2-d array
   public void displaySeats()
   {
       // print header, that requires no changing
       System.out.println(" Seats");
       System.out.println(" 123456789012345678901234567890");
       // use for loop to print out row by row and then its rows contents
       for (int i = 0; i < NUMROWS; i++)
       {
           // print out what row you're in, dont go to next line.
           System.out.print("Row " + (i+1) + " ");
           for (int j = 0; j < NUMCOLUMNS; j++)
           {
               // print out each content of that row
               System.out.print(seats[i][j]);
           }
           // go to new line
           System.out.print(" ");
       }
       // print out the legend
       System.out.println(" Legend: * = Sold/Occupied");
       System.out.println(" # = Available");
   }
  
   // method to display sales report
   public void displaySalesReport()
   {
       // print heading up to the first requirement of variable
       System.out.println("Gammage Sales Report _______________________________ Seats Sold: " + seatsSold +
               " Seats available: " + (450-seatsSold) + " Total revenue to date: $" + totalRevenue);
      
   }
}

*******************************************************************************************

4. Assignment8.java

import java.util.*;

public class Assignment8
{
   public static void main(String[] args)
   {
       // declare variables to control menu
       int usersChoice = 0;
       Scanner scan = new Scanner(System.in);
       // declare and instantiate a TicketManager object:
       TicketManager objectDone = new TicketManager();


       do
       {
       // display menu
       printMenu();
   // ask the user to choose a command
           System.out.println(" Please enter a command:");
   usersChoice = scan.nextInt();
           switch (usersChoice)
       {
       case 1:
           // just has to print the seats
           objectDone.displaySeats();
       break;
       case 2:
           // three variables, seatsDesired, rowDesired, startingSeat
           int seatsDesired = 0;
           int rowDesired = 0;
           int startingSeat = 0;
           // asks the three respective questions:
           System.out.print("Number of seats desired (1 - 30): ");
           seatsDesired = scan.nextInt();
           System.out.print(" Desired row (1 - 15): ");
           rowDesired = scan.nextInt();
           System.out.print(" Desired starting seat number in the row (1 - 30): ");
           startingSeat = scan.nextInt();
          
           // check if available
           if(objectDone.requestTickets(seatsDesired, rowDesired, startingSeat))
               System.out.println("The seats you have requested are available for purchase. ");
           else
           {
               System.out.println("Unfortunately, the seats you have requested are not available for purchase.");
               break;
                  }
          
           // Ask if they would like to buy, store in variable answer
           char answer = ' ';
           System.out.print("Do you wish to purchase these tickets (Y/N)? ");
           answer = scan.next().charAt(0);
           // if yes, print out like the receipt = purchase tickets method, then print stuff, then prink tickets.
           if (answer == 'Y' || answer == 'y')
           {
               // variable for total ticket cost
               double totalTicketCost = (seatsDesired*objectDone.getPrice(rowDesired));
               // print out stuff before the ticket print
               objectDone.purchaseTickets(seatsDesired, rowDesired, startingSeat);
               System.out.println("Num Seats: " + seatsDesired);
               System.out.println("The price for the requested tickets is $" + totalTicketCost);
               System.out.println("Please input amount paid: ");
               // amount to use as payment store in double
               double amountPaid = scan.nextDouble();
               // well its supposed to be an input but u dont use it as one so just setting it to whatever then
               //double amountPaid = 200;
              
               // print the ticket
               objectDone.printTickets(seatsDesired, rowDesired, startingSeat);
               // summary of stuff after ticket
               System.out.println("Tickets purchased: " + seatsDesired);
               System.out.println("Payment : $ " + amountPaid);
               System.out.println("Total ticket price : $" + totalTicketCost);
               System.out.println("Change due : $" + (amountPaid - totalTicketCost));
           }
           else
               break;
       break;

       case 3:
           objectDone.displaySalesReport();
       break;
       case 4:
           System.exit(0);
           break;
                   default:
                       System.out.println("Invalid choice!");
                       break;
       }
       } while (usersChoice != 4);
       scan.close();
   } // end main method
  
   public static void printMenu()
   {
       System.out.println("ASU Gammage Theater 1. View Available Seats 2. Request Tickets 3. Display Theater Sales Report 4. Exit the Program");
   } // end printMenu method
} // end class

Compile: javac Assignment8.java

Execute: java Assignment8 (or) java -Xms128M -Xms16M Assignment8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote