Self-Test 5

Wed, Nov. 24 2010

Exercise:

Today we will create and test a class to represent a concert, depicted in the following UML class diagram:

Concert

- band : String
- numSeats : int
- numTicketsSold : int
- ticketPrice : double
- totalSales : double


+ setBand(String band) : void
+ setNumSeats(int numSeats) : void
+ setTicketPrice(double ticketPrice) : void
+ getBand() : String
+ getNumSeats() : int
+ getTicketPrice() : double
+ getTicketsSold() : int
+ getTicketsLeft() : int
+ getTotalSales() : double
-  okToSell(int numTickets) : boolean
+ sellTickets(int toSell) : void
+ toString() : String
+ equals(Concert otherConcert) : boolean


  1. Write a stub for each method, like this:

    public void setBand(String band)
    {
        // stub - replace with code
    }

    public String getBand()
    {
        // stub - replace with code
        return null;
    }

  2. Start filling in the method bodies.  I have provided some junit tests for you (ConcertTest.java).  Compile and test often.

  3. One test has not been implemented (testGetTotalSales2). Write this test so that it buys tickets at different prices (for example 4 tickets at €32.50 and 2 tickets at €27.00), then makes an assertion about the expected sales amount.