Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a Ticket class that represents a ticket to attend an on-campus event. Define a new class called StudentTicket that extends ticket through inheritance. Adhere

Design a Ticket class that represents a ticket to attend an on-campus event. Define a new class called StudentTicket that extends ticket through inheritance. Adhere to given TicketTest.java.

image text in transcribed

TicketTest.java (Please use given TicketTest.java to test as Ticket.java & StudentTicket.java must adhere to the requirements of this)

/* TCSS 143 Driver Program for Lab 3 (Prints the following to the output) Ticket Price: 90.0 Days Early: 14 Promotion Code: KEXP call-in winner (student) Ticket Price: 55.0 Days Early: 40 Promotion Code: Ticket Price: 90.0 Days Early: 14 Promotion Code: KEXP call-in winner (student) Ticket t1 and Ticket t2 are equal: false Ticket t1 and Ticket t3 are equal: true */

public class TicketTest { public static void main(String[] args) { // Create a Student Ticket StudentTicket t1 = new StudentTicket(90); t1.setPromotionCode("KEXP call-in winner"); System.out.println(t1); // Generate a general ticket Ticket t2 = new Ticket(55, 40); System.out.println(t2); // Generate a student ticket StudentTicket t3 = new StudentTicket(90); t3.setPromotionCode("KEXP call-in winner"); System.out.println(t3); // Check for equality System.out.println("Ticket t1 and Ticket t2 are equal: " + t1.equals(t2)); // Should return false System.out.println("Ticket t1 and Ticket t3 are equal: " + t1.equals(t3)); // Should return true } }

Design a Ticket class that represents a ticket to attend an on-campus event. A ticket has a price and stores how many days early the ticket was bought (how many days before the 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 price Each ticket must have a price and how early it was daysEarly promotionCode purchased. Promotion code is set for specific tickets using an appropriate setter. public Ticket (double price, Constructs a ticket with the given price, purchased int daysEarly) the given number of days early, with no promotion code, and increments the ticket counter. (throws exception if ticket price is below 0) public int getDaysEarly Returns how many days early the ticket was bought Returns the ticket's price Returns the ticket's promotion code (if none) public double getPrice) public string get PromotionCode () public void set PromotionCode (String code) Sets the ticket's promotion code to the given value (throws an exception if null is passed) Returns a string representation of the ticket in the format: public String toString() Ticket Price: 45.0 Days Early: 14 Promotion Code: KEXP call-in winner Return true if the days, price, promotion code match public boolean equals (Object other) Define a new class called Student Ticket 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. 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 store "KEXP call-in winner (student)". . You should provide the same methods as the superclass, as well as the following new behavior. Constructor/Method public Student Ticket (double Description constructs a student ticket with the given base price price) public boolean equals(object other) returns true if this ticket is for a student and the days, price, promotion code matches 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 check for equality of StudentTicket objects by overriding the equals() method. If the two objects have the same price, same days, and promotion code, they are "equal". A driver program Ticket Test.java is provided to test if your program (Ticket.java and StudentTicket.java) adhere to the requirements provided in this document

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Show that isomorphism of simple graphs is an equivalence relation.

Answered: 1 week ago