Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I just need help with part 2 (the code below is from part 1) public abstract class Ticket { int numTickets; double price; public Ticket(int

image text in transcribed

image text in transcribed

I just need help with part 2

(the code below is from part 1)

public abstract class Ticket { int numTickets; double price; public Ticket(int numTickets) { this.numTickets = numTickets; } public int getNumTickets() { return numTickets; } public void setNumTickets(int numTickets) { this.numTickets = numTickets; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } @Override public String toString() { return numTickets + "tickets"; } } package chg; public class WalkUpTicket extends Ticket{ public WalkUpTicket(int numTickets) { super(numTickets); this.setPrice(50); // TODO Auto-generated constructor stub } @Override public String toString() { return numTickets + " same-day tickets at $50 is "+numTickets*50 ; } } package chg; public class AdvanceTicket extends Ticket { static int days; public AdvanceTicket(int numTickets,int daysIn) { super(numTickets); this.days=daysIn; if(days >= 10) { this.setPrice(30); } else if(days == 1) { this.setPrice(50); } else { this.setPrice(40); } // TODO Auto-generated constructor stub } @Override public String toString() { return numTickets+" advance tickets at $"+price+" is "+numTickets*price; } } package chg; public class StudentAdvTicket extends AdvanceTicket{ public StudentAdvTicket(int numTickets, int daysIn) { super(numTickets, daysIn); if(days >= 10) { this.setPrice(30); } else if(days == 1) { this.setPrice(50); } else { this.setPrice(40); } // TODO Auto-generated constructor stub } @Override public String toString() { return super.toString()+ " Student Id Required"; } }

AP Computer Science Lab: Tickets Part 1: Write the following classes from the UMLs. See additional information below. Ticket (Italics = abstract) int num Tickets double price Ticket(int numin) int getNum Tickets() double getPrice) void setPrice(double priceln) String toString() The toString method returns num Tickets + "tickets". WalkUpTicket WalkUp Ticket(int numin) String toString() Advance Ticket static int days Advance Ticket(int numin, int daysIn) String toString() Student Adv Ticket StudentAdvTicket(int numin, int daysn) String toString() WalkUpTicket: Walk-up tickets are purchased the day of the event and cost $50. The toString method should return "num Tickets same-day tickets at $50 is Advance Ticket: Advance tickets purchased 10 or more days before the event cost $30, and advance tickets purchased fewer than 10 days before the event cost $40. (Tickets purchased on the day of the event are Walk- up tickets.) The toString method should return "num Tickets advance tickets at $ is " StudentAdvTicket: Student advance tickets are sold at half the price of normal advance tickets: 10 or more days early are $15 and fewer than 10 days are $20. Same day student tickets are Walk-up tickets. The toString method should return the same information format as Advance Ticket, with the addition of "Student ID Required". (Use the parent toString() method.) *Have the constructors set the price. Part 2: Create runner class called Tickets. Print out a welcome statement. Import the Scanner and prompt the user to input the number of days in advance they are purchasing the tickets, along with the number of student and non-student tickets needed. Print out the appropriate object(s). Print out the total price. Run the program 3 times: 1) Enter 0 days and 5 tickets (3 are student tickets) 2) Enter 3 days and order 5 tickets (3 are student tickets) 3) Enter 12 days and order 8 tickets (6 are student tickets) Total = $250 Total = $140 ($80 + $60) Total = $150 ($60 + $90)

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

(3) An example of negative feedback that you received well.

Answered: 1 week ago

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago