Question

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 of Ticket Create the following classes for the 4 types of tickets: Adult, Child, Employee, MeviePass. may contain additional instance variables appropriate for the type of ticket. They will extend from Ticket and define the calculateTicketPrice and getld methods. The Adult and Child classes do not require an id, so getId will return a -1. There should be getters and setters for the instance variables, and any other methods that are needed for your design. The .toString method and constructors for these classes will use the super reference to take advantage of the Ticket constructor and toString methods. Use finals to represent constants.Need help to create general class

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

Complete Class Structure of the given description:

abstract class Ticket
{
   protected enum Format {ADULT, CHILD, EMPLOYEE, MOVIEPASS};
   protected Format typeOfTicket;
   protected double priceOfTicket;
   protected int ageOfPerson;
   protected int idOfPerson;
  
   public Ticket()
   {}

   public Ticket(Format typeOfTicket, double priceOfTicket, int ageOfPerson, int idOfPerson)
   {
       this.typeOfTicket = typeOfTicket;
       this.priceOfTicket = priceOfTicket;
       this.ageOfPerson = ageOfPerson;
       this.idOfPerson = idOfPerson;
   }

   public Format getTypeOfTicket()
   {
       return typeOfTicket;
   }
  
   public void setTypeOfTicket(Format typeOfTicket)
   {
       this.typeOfTicket = typeOfTicket;
   }
  
   public double getPriceOfTicket()
   {
       return priceOfTicket;
   }
  
   public void setPriceOfTicket(double priceOfTicket)
   {
       this.priceOfTicket = priceOfTicket;
   }
  
   public int getAgeOfPerson()
   {
       return ageOfPerson;
   }
  
   public void setAgeOfPerson(int ageOfPerson)
   {
       this.ageOfPerson = ageOfPerson;
   }
  
   public int getIdOfPerson()
   {
       return idOfPerson;
   }
  
   public void setIdOfPerson(int idOfPerson)
   {
       this.idOfPerson = idOfPerson;
   }
      
   @Override
   public String toString()
   {
       return "Ticket [typeOfTicket=" + typeOfTicket + ", priceOfTicket=" + priceOfTicket + ", ageOfPerson="
               + ageOfPerson + ", idOfPerson=" + idOfPerson + "]";
   }

   public abstract double calculateTicketPrice();
   public abstract int getId();
}

class Adult extends Ticket
{  
   public Adult()
   {
       super();
   }
  
   public Adult(Format typeOfTicket, double priceOfTicket, int ageOfPerson, int idOfPerson)
   {
       super(typeOfTicket, priceOfTicket, ageOfPerson, idOfPerson);
   }

   @Override
   public double calculateTicketPrice()
   {
       return 0;
   }

   @Override
   public int getId()
   {
       return -1;
   }

   @Override
   public String toString()
   {
       return "Adult [typeOfTicket=" + typeOfTicket + ", priceOfTicket=" + priceOfTicket + ", ageOfPerson="
               + ageOfPerson + ", idOfPerson=" + idOfPerson + "]";
   }  
}

class Child extends Ticket
{  
   public Child()
   {
       super();
   }
  
   public Child(Format typeOfTicket, double priceOfTicket, int ageOfPerson, int idOfPerson)
   {
       super(typeOfTicket, priceOfTicket, ageOfPerson, idOfPerson);
   }

   @Override
   public double calculateTicketPrice()
   {
       return 0;
   }

   @Override
   public int getId()
   {
       return -1;
   }

   @Override
   public String toString()
   {
       return "Child [typeOfTicket=" + typeOfTicket + ", priceOfTicket=" + priceOfTicket + ", ageOfPerson="
               + ageOfPerson + ", idOfPerson=" + idOfPerson + "]";
   }      
}

class Employee extends Ticket
{  
   public Employee()
   {
       super();
   }
  
   public Employee(Format typeOfTicket, double priceOfTicket, int ageOfPerson, int idOfPerson)
   {
       super(typeOfTicket, priceOfTicket, ageOfPerson, idOfPerson);
   }

   @Override
   public double calculateTicketPrice()
   {
       return 0;
   }

   @Override
   public int getId()
   {
       return 0;
   }

   @Override
   public String toString()
   {
       return "Employee [typeOfTicket=" + typeOfTicket + ", priceOfTicket=" + priceOfTicket + ", ageOfPerson="
               + ageOfPerson + ", idOfPerson=" + idOfPerson + "]";
   }
}

class MoviePass extends Ticket
{  
   public MoviePass()
   {
       super();
   }
  
   public MoviePass(Format typeOfTicket, double priceOfTicket, int ageOfPerson, int idOfPerson)
   {
       super(typeOfTicket, priceOfTicket, ageOfPerson, idOfPerson);
   }

   @Override
   public double calculateTicketPrice()
   {
       return 0;
   }

   @Override
   public int getId()
   {
       return 0;
   }

   @Override
   public String toString()
   {
       return "MoviePass [typeOfTicket=" + typeOfTicket + ", priceOfTicket=" + priceOfTicket + ", ageOfPerson="
               + ageOfPerson + ", idOfPerson=" + idOfPerson + "]";
   }  
}

Add a comment
Know the answer?
Add Answer to:
Need help to create general class Classes Data Element - Ticket Create an abstract class called...
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
  • 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...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

  • An abstract class doesn't have a constructor (because you cannot make an object of the abstract...

    An abstract class doesn't have a constructor (because you cannot make an object of the abstract class). It should have at least one method, which then has to be overridden in all derived classes. Here is an example:   abstract void run();   class Honda4 extends Bike{   public static void main(String args[]){   obj.run();   } You are to create an abstract class called Shape, which has an abstract method called computeArea(). Derive a Circle class from Shape. (Circle is similar to your previous...

  • java. Question 2: Practice Polymorphism- Food A Assume you have a parent class called Food with...

    java. Question 2: Practice Polymorphism- Food A Assume you have a parent class called Food with one instance data variable: private String name. The class has one constructor that takes the name as a parameter, getters and setters for name, and a toString that outputs the name. Write a child class called Vegetable with one additional variable describing whether or not the vegetable is green. Write two constructors: one that takes in all information about a vegetable and one that...

  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

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