Question

In: Computer Science

I want this program written in JAVA with the algorithm(The step by step process for the...

I want this program written in JAVA with the algorithm(The step by step process for the problem) . Please help it is due in a couple of hours. I don't want the C++ program, I want it in JAVA please

#20 Theater Ticket Sales

Create a TicketManager class and a program that uses it to sell tickets for a single performance theater production.


Here are the specifications:
• The theater's auditorium has 15 rows, with 30 seats in each row. To represent the seats, the TicketManager class should have a two-dimensional array of SeatStructures. Each of these structures should have data members to keep track of the seat's price and whether or not it is available or already sold.
• The data for the program is to be read in from two files located in the Chapter 8 programs folder on this book's companion website. The first one, SeatPrices.dat, contains 15 values representing the price for each row. All seats in a given row are the same price, but different rows have different prices. The second file, SeatAvailability. dat, holds the seat availability information. It contains 450 characters (15 rows with 30 characters each), indicating which seats have been sold (' • ') and which are available ( '#' ). Initially all seats are available. However, once the program runs and the file is updated, some of the seats will have been sold. The obvious function to read in the data from these files and set up the array is the constructor that runs when the TicketManager object is first created.
• The client program should be a menu-driven program that provides the user with a menu of box office options, accepts and validates user inputs, and calls appropriate class functions to carry out desired tasks. The menu should have options to display the seating chart, request tickets, print a sales report, and exit the program.
• When the user selects the display seats menu option, a TicketManager function should be called that creates and returns a string holding a chart, similar to the one shown here. It should indicate which seats are already sold ( *) and which are still available for purchase (#) . The client program should then display the string.

Seats 1234567890 12345678901234567890

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 ##############################
• When the user selects the request tickets menu option , the program should prompt for the number of seats the patron wants, the desired row number, and the desired starting seat number. A TicketManager ticket request function should then be called and passed this information so that it can handle the ticket request. If any of the requested seats do not exist, or are not available, an appropriate message should be returned to be displayed by the client program. If the seats exist and are available, a string should be created and returned that lists the number of requested seats, the price per seat in the requested row, and the total price for the seats. Then the user program should ask if the patron wishes to purchase these seats.
• If the patron indicates they do want to buy the requested seats , a TicketManager purchase tickets module should be called to handle the actual sale. This module must be able to accept money, ensure that it is sufficient to continue with the sale, and if it is, mark the seat(s) as sold, and create and return a string that includes a ticket for each seat sold (with the correct row, seat number, and price on it).
• When the user selects the sales report menu option, a TicketManager report module should be called. This module must create and return a string holding a report that tells how many seats have been sold, how many are still available, and how much money has been collected so far for the sold seats. Think about how your team will either calculate or collect and store this information so that it will be available when it is needed for the report.
• When the day of ticket sales is over and the quit menu choice is selected, the program needs to be able to write the updated seat availability data back out to the file. The obvious place to do this is in the TicketManager destructor.

Solutions

Expert Solution

Program code to copy

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();
      
       // display menu
       printMenu();
      
       do
       {
            // ask the user to choose a command
           System.out.println("\nPlease 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("\nDesired row (1 - 15): ");
                       rowDesired = scan.nextInt();
                       System.out.print("\nDesired 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();
              
                           // print the ticket
                           objectDone.printTickets(seatsDesired, rowDesired, startingSeat);
                           // summary of stuff after ticket
                           System.out.println("Tickets purchased: " + seatsDesired);
                           System.out.println("Payment\t\t\t: $ " + amountPaid);
                           System.out.println("Total ticket price \t: $" + totalTicketCost);
                           System.out.println("Change due\t\t: $" + (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\n1. View Available Seats\n2. Request Tickets\n3. Display Theater Sales Report\n4. Exit the Program");
   } // end printMenu method
} // end class

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

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 (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
       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("\t\t\tSeats");
       System.out.println("\t123456789012345678901234567890");
       // 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) + "\t");
           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("\n");
       }
       // print out the legend
       System.out.println("\tLegend: * = Sold/Occupied");
       System.out.println("\t# = Available");
   }
  
   // method to display sales report
   public void displaySalesReport()
   {
       // print heading up to the first requirement of variable
       System.out.println("Gammage Sales Report \n _______________________________\n Seats Sold: " + seatsSold +
               "\nSeats available: " + (450-seatsSold) + "\nTotal revenue to date: $" + totalRevenue);
      
   }
}

===================================================================================
seatAvailability.txt

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

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

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

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

Program Screenshot

Assignment8.java

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

TicketManager.java

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

seatAvailability.txt

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

seatPrices.txt

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

Sample output


Related Solutions

An algorithm (like a computer program) is a step-by-step process to accomplish some task. True False...
An algorithm (like a computer program) is a step-by-step process to accomplish some task. True False 2 points    QUESTION 2 All components of an array must be of the same type (all int, all double, all string, etc.). True False 2 points    QUESTION 3 A group of objects defined from the same class will all have different properties and different methods. True False 2 points    QUESTION 4 Each instance of an object from a particular class is...
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...
i want a program in java that finds the shortest path in a 2D array with...
i want a program in java that finds the shortest path in a 2D array with obstacles from source to destination using BFS and recursion. The path must be stored in a queue. The possible moves are left,right,up and down.
I want to update this JAVA program to : Exit cleanly, and change the pie chart...
I want to update this JAVA program to : Exit cleanly, and change the pie chart to circle rather than an oval, and provide a separate driver please and thank you import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.Scanner; import javax.swing.JComponent; import javax.swing.JFrame; // class to store the value and color mapping of the // pie segment(slices) class Segment { double value; Color color; // constructor public Segment(double value, Color color) { this.value = value; this.color = color;...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Hi I have an exercise and I want to you to solve it step by step,...
Hi I have an exercise and I want to you to solve it step by step, please.. I found the solution here but it did not have steps .. *Answer the following questions using the information below: Tiger Pride produces two product lines: T-shirts and Sweatshirts. Product profitability is analyzed as follows: T-SHIRTS SWEATSHIRTS Production and sales volume 60,000 units 35,000 units Selling price $16.00 $29.00 Direct material $ 2.00 $ 5.00 Direct labor $ 4.50 $ 7.20 Manufacturing overhead...
please I want it to step by step and in word posted so I can read...
please I want it to step by step and in word posted so I can read them. Q: If the average realized return of a portfolio is 27.5% per year, the standard deviation of returns is 50%, the portfolio beta is 1.25, the average return of Treasury bills over the same period is 2.5% per year, and the average return on the market is 12.5% per year Calculate i) the Sharpe; ii) Treynor and iii) Jensen    
Can I please get a step by step (either video or written out) for this question....
Can I please get a step by step (either video or written out) for this question. I don't know where to find the step by step videos. They are EXTREMELY helpful. The inverse demand for a homogeneous-product Stackelberg duopoly is P = 16,000 -4Q. The cost structures for the leader and the follower, respectively, are CL(QL) = 3,000QL and CF (QF) = 6,000QF.. a. What is the follower’s reaction function? b. Determine the equilibrium output level for both the leader...
Hello, I am writing the initial algorithm and refined algorithm for a program. I just need...
Hello, I am writing the initial algorithm and refined algorithm for a program. I just need to make sure I did it correctly. I'm not sure if my formula is correct. I appreciate any help, thank you! TASK: Write a program that will calculate the final balance in an investment account. The user will supply the initial deposit, the annual interest rate, and the number of years invested. Solution Description: Write a program that calculates the final balance in an...
This program is written in Java and should be modularized in methods in one class. This...
This program is written in Java and should be modularized in methods in one class. This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. INPUT The application must be able to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT