Question

CMSC 256 – Project 5 Programming Assignment 5 Note: When you turn in an assignment to...

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.

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

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

Add a comment
Know the answer?
Add Answer to:
CMSC 256 – Project 5 Programming Assignment 5 Note: When you turn in an assignment to...
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...

  • CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz...

    CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz program from the previous assignment. You will create an abstract class called "Question", modify "MultipleChoiceQuestion" to inherit from it, and add a new subclass of "Question" called "TrueFalseQuestion". This assignment will again involve cutting and pasting from existing classes. Because you are learning new features each week, you are retroactively applying those new features. In a typical programming project, you would start with the...

  • CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz...

    CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz program from the previous assignment. You will create an abstract class called "Question", modify "MultipleChoiceQuestion" to inherit from it, and add a new subclass of "Question" called "TrueFalseQuestion". This assignment will again involve cutting and pasting from existing classes. Because you are learning new features each week, you are retroactively applying those new features. In a typical programming project, you would start with the...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

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

  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of...

    Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of the class of the objects to be sorted. Several methods can be written for comparing the objects according to different criteria. Specifically, write three classes, DescriptionComparator, FirstOccComparator, and LastOccComparator that implement the interface java.util.Comparator. DescriptionComparator implements the interface Comparator. The method compare compares the description of two objects. It returns a negative value if the description of the first object comes before the description...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • please use java do what u can 1. Modify the Student class presented to you as...

    please use java do what u can 1. Modify the Student class presented to you as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called set Test Score that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called get...

  • Project 4: Pet Store Objectives: Create multiple classes in an inheritance hierarchy Use an abstract class...

    Project 4: Pet Store Objectives: Create multiple classes in an inheritance hierarchy Use an abstract class Use polymorphism Use an ArrayList Assignment For this project, you get to write a simplified pet store inventory program in Java. To complete this, you will need to have the following classes: Main class PetStore class Pet class Bird class Reptile class Snake class Turtle class Main class: This class is a driver class for the PetStore class. It is not part of the...

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