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
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