Question

Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing...

Ticket Hierarchy

Ticket Abstract Class

  • Create a static variable called nextTicketId. This is an integer representing the next available integer for the ticketId

                                private static int nextTicketId = 1000;

  • getPrice method: Abstract method that returns a double. NOTE: Do not make price an instance variable in Ticket.
  • Noargument constructor: Sets event name to “none”, event location to “none”, and ticket id to 0.
  • Create a constructor that accepts the event name and event location as parameters. Set the ticket Id to the nextTicketId available. Then, increment the nextTicketId.
  • Generate getters and setters for the 3 instance variables: event name, event location, and ticket id Override toString from the Object class: The following example shows the format you should use:                          “Event name: Concert, Event location: Civic Center, Ticket Id: 1000, Price: 50.0”

WalkupTicket Class              

  • Create a noargument constructor
  • Create a constructor that accepts the event name and event location
  • Override the Ticket toString() o It should invoke super.toString() and be in this format:

WalkupTicket Event name: Concert, Event location: Civic Center, Ticket Id: 1000, Price: 50.0 -          These tickets always cost $50 each. Override the getPrice() method for this subclass. Use a constant.

AdvanceTicket Class

  • Add an instance variable that stores the number of days in advance that the ticket was purchased. Generate getter and setter for new instance variable
  • Create a noargument constructor
  • Create a constructor that accepts the event name, event location, and number of days in advance that the ticket was purchased.
  • 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. Override the getPrice() method for this subclass. Use constants
  • These tickets are nonrefundable. Override toString for this subclass to clearly indicate this and make sure that you invoke super.toString(). The following example shows the format you should use:

         “AdvanceTicket Event name: Concert, Event location: Civic Center, Ticket Id: 1000, Price: 30.0 (*Nonrefundable Ticket *)”

TicketTester Class

  • Create 4 WalkupTicket objects using a Ticket reference. For example:

     Ticket ticket1 = new WalkupTicket(“Concert”, “Civic Center”);

  • Create 4 AdvanceTicket objects using a Ticket reference. For example:

     Ticket ticket5 = new AdvanceTicket(“Graduation”, “LVIS”, 5);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Tester:


public class TicketTester {

   public static void main(String[] args) {
       for(int i = 1; i <= 4; i++)
           Ticket ticket1 = new WalkupTicket("Concert", "Civic Center");
       for(int i = 1; i <= 4; i++)
           Ticket ticket5 = new AdvanceTicket("Graduation", "LVIS", 5);
   }

}


ADvancedTicket:

public class AdvanceTicket extends Ticket{
   private static final int beforeTen = 30;
   private static final int afterTen = 40;
  
   int inAdvance;
  
   AdvanceTicket() {
       super();
       inAdvance = 0;
   }
  
   AdvanceTicket(String event, String place, int inAdvance) {
       super(event, place);
       this.inAdvance = inAdvance;
   }
  
   @Override
   public int getPrice() {
       if(inAdvance >= 10)
           return beforeTen;
       return afterTen;
   }
  
   public int getAdvance() {
       return inAdvance;
   }
  
   public void setAdvance(int x) {
       inAdvance = x;
   }
  
   @Override
   public String toString() {
       return "dvanceTicket " + super.toString() + "(*Nonrefundable Ticket *)";
   }
}

WalkupTicket

public class WalkupTicket extends Ticket{
  
   private static final int price = 50;
  
   WalkupTicket() {
       super();
   }
  
   WalkupTicket(String event, String place) {
       super(event, place);
   }
  
   @Override
   public int getPrice() {
       return price;
   }
  
   @Override
   public String toString() {
       return "WalkupTicket " + super.toString();
   }
}

Ticket

public class Ticket extends Object{
   private static int nextTicketId = 1000;
  
   private String eventName, location;
   private int ID;
  
   Ticket() {
       eventName = "none";
       location = "none";
       ID = 0;
   }
  
   Ticket(String event, String place) {
       eventName = event;
       location = place;
       ID = nextTicketId;
       nextTicketId++;
   }
  
   public int getPrice() {
       return 0;
   }
  
   public String getEventName() {
       return eventName;
   }
  
   public void setEventName(String s) {
       eventName = s;
   }
  
   public String getLocation() {
       return location;
   }
  
   public void setLocation(String s) {
       location = s;
   }
  
   public int getID() {
       return ID;
   }
  
   public void setID(int x) {
       ID = x;
   }
  
   @Override
   public String toString() {
       return "Event name: "+eventName+", Event location: "+location+", Ticket Id: "+ID+", Price: "+getPrice();
   }
}




Comment down for any queries

Please give a thumb up

Add a comment
Know the answer?
Add Answer to:
Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • CMSC 256 – Project 5 Programming Assignment 5 Note: When you turn in an assignment to...

    CMSC 256 – Project 5 Programming Assignment 5 Note: When you turn in an assignment to be graded in this class, you are making the claim that you neither gave nor received assistance on the work you turned in (except, of course, assistance from the instructor or teaching assistants). Program: Ticketing System Points: 100 A set of classes is used to handle the different ticket types for a theater event. All tickets have a unique serial number that is assigned...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email...

    Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email address Present Number of hours 3.5 - 18 Two constructors should be coded, one that accepts no arguments and sets every field to its default value, and one that accepts all four fields, and assigns the passed values into the instance variables. For each instance variable create two methods; a getter and a setter. Add a static method to the class that will accept...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT