Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following program represents tickets for sporting events sold by the university stadium. Tickets are less expensive when ordered in advance and students get a

The following program represents tickets for sporting events sold by the university stadium. Tickets are less expensive when ordered in advance and students get a 50% discount on advance tickets. Several classes work together via inheritance to provide this functionality used by the ticket booth operators. Read all of the classes before typing in the missing code.
=====Ticket Superclass=====
public
class Ticket {
protected int serialNum;
private static num =0;
public Ticket(){
= getNextSerialNum();
}
public abstract double getPrice();
public
toString(){
"Number: "+ serialNum +"
Price: "+ getPrice();
}
private static int getNextSerialNum(){
num++;
serialNum =
;
return serialNum;
}
}
=====Walkup Subclass=====
public class
extends Ticket{
private double price =20.00;
public Walkup(){
super();
}
public
getPrice(){
return price;
}
}
=====Advance Subclass=====
public class Advance extends Ticket{
private double price;
private int days;
public Advance(int d){
;
days =
;
}
public double getPrice(){
if (days >=10)
price =10.0;
price =15.0;
return price;
}
}
=====StudentAdvance Subclass=====
public class StudentAdvance
{
public StudentAdvance(int d){
super(d);
}
public double getPrice(){
return
.getPrice()/2;
}
public String toString(){
return super.toString()+"
(student ID required)";
}
}
=====Driver Class TicketBooth=====
import java.util.Scanner;
public class TicketBooth {
public static void main(String[] args){
Scanner scan =
;
ArrayList tix = new ArrayList();
int choice, days;
temp;
System.out.println("Welcome ticket booth operator!
Just type the ticket type number to generate a ticket.");
System.out.println("Menu:
1)Walkup Ticket
2)Advance Ticket
3)Student Advance Ticket
0)Quit");
choice =
;
scan.nextLine();
while (
!=0){
if (choice >1){
System.out.println("Number of days until the show?");
= scan.nextInt();
scan.nextLine();
if (choice ==2){
temp = new
(days);
} else {
temp = new StudentAdvance(days);
}
} else {
temp = new Walkup();
}
tix.add(
);
System.out.println(temp);
System.out.println("Welcome ticket booth operator!
Just type the ticket type number to generate a ticket.");
System.out.println("Menu:
1)Walkup Ticket
2)Advance Ticket
3)Student Advance Ticket
0)Quit");
choice = scan.nextInt();
scan.nextLine();
}
}
}

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

Students also viewed these Databases questions