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 privat

ID: 3874067 • Letter: C

Question

Consider the following abstract Ticket class public abstract class Ticket private Date eventDate; II date of the show pblic Ticketate date)( eventDate- date public abstract double getPrice/ returns the price of this ticket public String toStringo return "Date:" + eventDate.toString)+"nPrice:" +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 sub- class, 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.

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//Ticket.java class

import java.util.Date;

/**

* Abstract class Ticket

*

*/

public abstract class Ticket {

      private Date eventDate;

      public Ticket(Date eventDate) {

            this.eventDate = eventDate;

      }

      public abstract double getPrice();

      public String toString(){

            return "Date: "+eventDate.toString()+" Price: "+getPrice();

      }

}

//RegularTicket.java class

import java.util.Date;

public class RegularTicket extends Ticket{

      /**

      * Constructor with event Date which will be passed

      * to the super class Ticket

      */

      public RegularTicket(Date eventDate) {

            super(eventDate);      

      }

      public double getPrice() {

            /**

            * Price of a regular ticket- 10TLs

            */

            return 10d;

      }

}

//ReservedSeat.java class

import java.util.Date;

public class ReservedSeat extends Ticket {

      /**

      * variables to store row and seat numbers

      */

      private int rowNumber;

      private int seatNumber;

      /**

      * Constructor with arguments

      */

      public ReservedSeat(Date eventDate, int rowNumber, int seatNumber) {

            /**

            * Passing the Event Date to super class Ticket

            */

            super(eventDate);

            this.rowNumber = rowNumber;

            this.seatNumber = seatNumber;

      }

      public double getPrice() {

            if (rowNumber >= 1 && rowNumber <= 15) {

                  /**

                  * seat in rows 1-15 costs 30TLs

                  */

                  return 30d;

            } else {

                  /**

                  * other seats cost 20TLs

                  */

                  return 20d;

            }

      }

      public String toString() {

            /**

            * Appending the row and seat numbers to the String

            */

            return super.toString() + " Row Number: " + rowNumber

                        + " Seat Number: " + seatNumber;

      }

}

//StudentReservedSeat.java class

import java.util.Date;

public class StudentReservedSeat extends ReservedSeat {

      /**

      * Constructor with arguments

      */

      public StudentReservedSeat(Date eventDate, int rowNumber, int seatNumber) {

            /**

            * Passing values to the super class ReservedSeat

            */

            super(eventDate, rowNumber, seatNumber);       

      }

      @Override

      public double getPrice() {

            /**

            * Giving the discount of 5TLs to the normal price

            * Here, the super.getPrice() will fetch the price of

            * a normal ReservedSeat

            */

            return super.getPrice()-5d;

      }

     

}

//Test.java class

import java.text.ParseException;

import java.text.SimpleDateFormat;

/**

* A test class to demonstrate the working of Ticket classes

*/

public class Test {

      public static void main(String[] args) throws ParseException {

            Ticket t1,t2,t3;

            /**

            * Defining a SimpleDateFormat object to parse event Dates from simple String

            */

            SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");

            /**

            * Creating a regular ticket

            */

            t1=new RegularTicket(sdf.parse("02/12/2017"));

            /**

            * Creating a reserved ticket

            */

            t2=new ReservedSeat(sdf.parse("1/2/2018"), 10, 2);

            /**

            * Creating a student reserved ticket, discount will be applied automatically

            */

            t3=new StudentReservedSeat(sdf.parse("7/2/2018"), 10, 2);

            /**

            * Printing the three ticket details

            */

            System.out.println("Ticket one details (Regular Ticket) "+t1);

            System.out.println(" Ticket two details (Reserved Ticket) "+t2);

            System.out.println(" Ticket three details (Student Reserved Ticket) "+t3);

      }

}

/*OUTPUT*/

Ticket one details (Regular Ticket)

Date: Sat Dec 02 00:00:00 IST 2017

Price: 10.0

Ticket two details (Reserved Ticket)

Date: Thu Feb 01 00:00:00 IST 2018

Price: 30.0

Row Number: 10

Seat Number: 2

Ticket three details (Student Reserved Ticket)

Date: Wed Feb 07 00:00:00 IST 2018

Price: 25.0

Row Number: 10

Seat Number: 2

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