logo Practice-It logo

StudentTicket

Related Links:
Author: Marty Stepp (on 2010/12/28)

You have been asked to extend a pre-existing class Ticket that represents a ticket to attend an on-campus event. A ticket has a price and also stores how many days early the ticket was bought (how many days before its event takes place). Some tickets have "promotion codes" that can allow special access and benefits for the ticket holder.

The Ticket class includes the following members:

Member Description
private double price
private int daysEarly
private String promotionCode
private data of each ticket
public Ticket(double price, int daysEarly) constructs a ticket with the given price, purchased the given number of days early, with no promotion code
public int getDaysEarly() returns how many days early the ticket was bought
public double getPrice() returns the ticket's price
public String getPromotionCode() returns the ticket's promotion code ("" if none)
public void setPromotionCode(String code) sets the ticket's promotion code to the given value (throws an exception if null is passed)
public String toString() returns a string representation of the ticket

You are to define a new class called StudentTicket that extends Ticket through inheritance. A StudentTicket should behave like a Ticket except for the following differences:

  • Student tickets are always bought by the campus ticket sales agency, two weeks (14 days) ahead of the event.
  • Students always get a 1/2 price discount off the initial price of any ticket to any event.
  • Honor students get an additional $5 off the price after the 1/2 discount, down to a minimum cost of $0 (free).
  • Student tickets have special promotion codes. Any promotion code that is set on a student ticket should be modified to have the suffix " (student)" attached. For example, if the client sets the promotion code to "KEXP call-in winner", a student ticket should actually store "KEXP call-in winner (student)".

You should provide the same methods as the superclass, as well as the following new behavior.

Constructor/Method Description
public StudentTicket(double price, boolean honors) constructs a student ticket with the given base price, possibly for an honor student
public boolean isHonorStudent() returns true if this ticket is for an honor student

Note that some of the existing behaviors from Ticket should behave differently on StudentTicket objects, as described previously. You should appropriately utilize the behavior you have inherited from the superclass and not re-implement behavior that already works properly in the superclass.

You must also make StudentTicket objects comparable to each other using the Comparable interface. Student tickets are compared by price, breaking ties by promotion code. In other words, a StudentTicket object with a lower price is considered to be "less than" one with a higher price. If two tickets have the same price, the one whose promotion code comes first in alphabetical order is considered "less." (You should compare the strings as-is and not alter their casing, spacing, etc.) If the two objects have the same price and promotion code, they are considered to be "equal."

Type your solution here:


This is an inheritance problem. Write a Java class using inheritance. (You do not need to write any import statements.)

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.