Consider a class ConcertPromoter that records the tickets sold for a performance. Before the day of the concert, tickets are sold only over the phone. Sales on the day of the performance are made only in person at the concert venue. The class has the following attributes:
• The name of the band
• The capacity of the venue
• The number of tickets sold
• The price of a ticket sold by phone
• The price of a ticket sold at the concert venue
• The total sales amount
It has methods to
• Record the sale of one or more tickets
• Change from phone sales to sales at the concert venue
• Return the number of tickets sold
• Return the number of tickets remaining
• Return the total sales for the concert
a. Write a method heading for each method.
b. Write preconditions and postconditions for each method.
c. Write some Java statements that test the class.
d. Implement the class.
e. List any additional methods and attributes needed in the implementation that were not listed in the original design. List any other changes made to the original design.
f. Write a program using the class you wrote for Part d that will be used to record sales for a concert. Your program should record phone sales, then sales at the venue. As tickets are sold, the number of seats remaining should be displayed. At the end of the program, display the number of tickets sold and the total sales amount for the concert.
The motivation for this project is to introduce a simplified example of the kind of specialized programs students may encounter. We use a class to encapsulate the domain knowledge. The main method contains a simple text based interface that uses the class.
a) ```
public void sellTickets(int number)
public void phoneSalesOver()
public int getTicketsSold()
public int getTicketsLeft()
public double getTotalSales()
```
b)
public void sellTickets(int number)
Precondition: Then number of tickets requested is positive and less than the number of tickets unsold.
Postcondition: The number of tickets sold and total sales were updated.
public void phoneSalesOver()
Precondition: none.
Postcondition: Ticket sales can now be made only at the venue.
public int getTicketsSold()
Precondition: none.
Postcondition: The number of tickets sold was returned.
public int getTicketsLeft()
Precondition: none.
Postcondition: The number of unsold tickets was returned.
public double getTotalSales()
Precondition: none.
Postcondition: The total amount of sales was returned.
d) We need to add an attribute that will indicate whether ticket sales are over the phone or at the venue.
We will add the methods
public void initialize(String band, int max, double
costOverPhone, double costAtVenue)
Precondition: none.
Postcondition: All the attributes were initialized. The name of the band was set to band. The capacity of the venue was set to max. The number of tickets sold was set to zero. The cost of the tickets when ordered by phone and at the venue were set to the arguments. The sales total was set to zero. The attribute indicating where tickets are being sold was set to indicate sales over the phone.
public boolean phoneSalesOnly()
Precondition: none.
Postcondition: Returned true if we are only making sales over the phone, otherwise false.
public String getSalesReport()
Precondition: none.
Postcondition: Returned a string with the number of tickets sold and their amount.
public void doTicketSale()
Precondition: none.
Postcondition: Obtains a number of tickets to sell. Makes the sale if possible and reports the cost of the tickets.
public double getSaleCost(int number)
Precondition: The number of tickets requested is positive and less than the number of tickets unsold.
Postcondition: Returns the cost of the sale of that number of tickets.
We will change sellTickets slightly.
public boolean sellTickets(int number)
Precondition: The number of tickets requested is positive and less than the number of tickets unsold.
Postcondition: The number of tickets sold and total sales were updated. True is returned if the sale was finished, false otherwise.
See the code in ConcertPromoter.java.
You might also like to view...
A(n) ________ cable carries all audio and video information from devices to a connected TV
A) HDMI B) RJ11 C) S component D) Ethernet
You support a large, complicated network. After experiencing problems and testing the cabling, you have discovered a bad horizontal cable. What should you do next?
A. Replace the cable yourself. B. Leave the cable, string another cable. C. Find the break and repair it. D. Hire an experienced installer.