Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following abstract Ticket class. public abstract class Ticket { pri

ID: 3874099 • Letter: C

Question

Consider the following abstract Ticket class. public abstract class Ticket { private Date eventDate; // date of the show public Ticket(Date date) { eventDate = date; } public abstract double getPrice(); // returns the price of this ticket public String toString() { return "Date: " + eventDate.toString() + " Price: " + getPrice(); } }

This class was designed for the sale of theater tickets. As you probably know, there are different ticket categories at the theaters. For each question below , design and implement a concrete subclass, and provide a separate Java source file as your solution.

In addition to correctness and quality of design, in this homework, you will also be graded based on proper use of inheritance. That is, all relevant methods/properties of a subclass should be moved to the superclass as necessary.

Q1. (20 pts.) RegularTicket class A regular ticket costs 10 TLs. * Include a constructor that takes the event date.

Q2. (30 pts.) ReservedSeat class This is a ticket category that has a row number and a seat number. Rows 1 to 15 costs 30 TLs. Other reserved seat tickets cost 20 TLs. * Be careful with the String conversion method toString(). This method should display (in addition to date and price) row number and seat number fields. * Include a constructor that takes the event date, row number and seat number.

Q3. (50 pts.) StudentReservedSeat class When a student purchases a reserved seat, a discount in the amount of 5TLs will be applicable. * Make sure that the price is displayed correctly by the toString() method. * Include a constructor that takes the event date, row number and seat number. * The price of a student reserved seat should be based on the price of a reserved seat purchased by someone that is not a student. That is, if the getPrice() method of ReservedSeat is modified, that modification should be reflected to the price of a StudentReservedSeat automatically.

Explanation / Answer

Ticket.java

import java.io.*;
import java.util.*;


public abstract class Ticket{
private Date eventDate;
public Ticket(Date date){
      eventDate = date;
}
public abstract double getPrice();
public String toString(){
      return "Date:"+eventDate.toString() + " Price:"+getPrice();
}
}

RegularTicket.java

import java.io.*;
import java.util.*;

public class RegularTicket extends Ticket{

      public RegularTicket(Date date){

            super(date);
      }     
      public double getPrice(){
           return 10;
      }
}

ReservedSeat.java

import java.io.*;
import java.util.*;


public class ReservedSeat extends Ticket{
    private int rowNumber;
    private int seatNumber;

    public ReservedSeat(Date date, int row, int st){
         super(date);
         rowNumber = row;
         seatNumber = st;
    }
    public double getPrice(){
        if (rowNumber >= 1 && rowNumber <= 15)
           return 30;
        else
           return 20;
    }
    public String toString(){
        return super.toString() + " Row Number:" + rowNumber + " Seat Number:" + seatNumber;
       
    }

StudentReservedSeat.java

import java.io.*;
import java.util.*;

public class StudentReservedSeat extends ReservedTicket{

    public StudentReservedSeat(Date date, int row, int st){
         super(date,row,st);
    }
    public double getPrice(){
        return super.getPrice() - 5;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote