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

CMSC 256 – Project 5 Programming Assignment 5 Note: When you turn in an assignme

ID: 3779430 • Letter: C

Question

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 when the ticket is constructed and a price. There are many types of tickets as described in the following table: Ticket Type Description Ticket This is an abstract class representing all tickets FixedPriceTicket This is an abstract class representing tickets that are always the same price. The constructor accepts the price as the parameter. FreeTicket These tickets are free. (Thus this class is a subclass of FixedPriceTicket) WalkupTicket These tickets are purchased on the day of the event for $50. (Thus this class is a subclass of FixedPriceTicket) AdvanceTicket Tickets purchased ten or more days in advance cost $30.Tickets purchased fewer than ten days in advance cost $40. StudentAdvanceTicket These are AdvanceTickets that cost half of what an AdvanceTicket would normally cost. a. Design a class hierarchy that encompasses the above classes. Implement the Ticket abstract class. This class will store a serial number as its private data. Provide an abstract method to get the price of the ticket called getPrice, provide a method that returns the serial number called getSerialNumber, and provide an implementation of toString() that prints the serial number and price information. The Ticket class must provide a constructor that generates the serial number. To do so, use the following strategy: maintain a static ArrayList representing previously assigned serial numbers. Repeatedly generate a new serial number using a random number generator until you obtain a serial number not already assigned. b. Implement the FixedPriceTicket class. The constructor accepts a price. The class is abstract but you can and should implement the method that returns the price information. c. Implement the WalkupTicket class and the ComplementaryTicket class. d. Implement the AdvanceTicket class. Provide a constructor that takes a parameter indicating the number of days in advance that the ticket is being purchased. Recall that the number of days of advanced purchase affects the ticket price. e. Implement the StudentAdvanceTicket class. Provide a constructor that takes a parameter indicating the number of days in advance that the ticket is being purchased. The toString method should include a notation that this is a student ticket. This ticket costs half of an AdvanceTicket. If the pricing scheme for AdvanceTicket changes, the StudentAdvanceTicket price should be computed correctly with no code modification to the StudentAdvanceTicket class. f. Write a class TicketOrder that stores a collection of Tickets. TicketOrder should provide methods add, toString, and totalPrice. CMSC 256 – Project 5 g. Write a class Event that models any event that requires tickets for admission. An Event has a title, a date, the fixed ticket price for this event, a maximum number of tickets that can be sold for the event, and a list of the allowable ticket types for this event. Write this program in JAVA and compile it in JDK 7 or better. Follow all commenting conventions discussed in class and include a comment block at the top of each file with your name, date, the course number and section. It is expected that your program will be well documented and you are required to include a private helper method in your main class called printHeading that outputs the following information to the console in an easy-to-read format: your name, the project number, the course identifier, and the current semester. You will call this method as the first statement in your main method. You will upload the project source code files to the Assignment link in Blackboard.

Explanation / Answer

Following are the java classes:

package com.amdocs.project;

import java.util.ArrayList;

public abstract class Ticket {
private int serialNo;
static ArrayList<Integer> serial;

public Ticket() {
   int serialNo;
   while(true){
   serialNo=(int)Math.random()*10000000;
   if (!serial.contains(serialNo)){
       serial.add(serialNo);
       this.serialNo=serialNo;
       break;
   }
   }
}
abstract double getPrice();
public int getSerialNumber(){
   return this.serialNo;
}
@Override
public String toString(){
   return this.serialNo+""+getPrice();
}

}

package com.amdocs.project;

public abstract class FixedPriceTicket extends Ticket{
private double price;

public FixedPriceTicket(double price) {
   this.price = price;
}

/**
* @return the price
*/
public double getPrice() {
   return price;
}

/**
* @param price the price to set
*/

}

package com.amdocs.project;

public class FreeTicket extends FixedPriceTicket{
      
   public FreeTicket(double price) {
       // TODO Auto-generated constructor stub
       super(0);
      
   }

}

package com.amdocs.project;

public abstract class AdvanceTicket extends Ticket{
public int days;
public double price;
public AdvanceTicket(int days) {
   super();
   this.days = days;
}
public void ticketPrice(){
   if (days <10){
       this.price=50;
   }
   else{
       this.price=40;
   }
  
  
}
/**
* @return the days
*/
public int getDays() {
   return days;
}
/**
* @return the price
*/
public double getPrice() {
   return price;
}
}

package com.amdocs.project;

import java.util.ArrayList;
import java.util.Iterator;

public class TicketOrder {
private Ticket ticket;
ArrayList<Ticket> ticketCollect;

public void add(Ticket t){
   ticketCollect.add(t);
  
}
public double totalPrice(){
  
   double sum=0;
   for (Ticket t:ticketCollect){
       sum+=t.getPrice();
   }
   return sum;
}


}

package com.amdocs.project;

import java.util.ArrayList;
import java.util.Calendar;

public class Event {
private String title;
private Calendar date;
private int maxNo;
ArrayList<Ticket> ticket;
public Event(String title, Calendar date, int maxNo, ArrayList<Ticket> ticket) {
   super();
   this.title = title;
   this.date = date;
   this.maxNo = maxNo;
   this.ticket = ticket;
}


}

package com.amdocs.project;

public abstract class StudentAdvanceTicket extends AdvanceTicket{

   public StudentAdvanceTicket(int days) {
       super(days);
       // TODO Auto-generated constructor stub
   }
   public int days;
   public double price;
  
   public void ticketPrice(){
       if (days <10){
           this.price=50;
       }
       else{
           this.price=40;
       }
}
}