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

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

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

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.]...

    C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.] Write a rational number class. Recall that a rational number is a ratio-nal number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects...

  • In order to do Program 6, Program 5 should bemodified.Program 6

    In order to do Program 6, Program 5 should be modified.Program 6-----------------------------------Program 4----------------------------------------------- (abstract class exception handling) Modify program4 to meet the following requirements: I. Make Person, Employee classes to abstract classes. Cl0%) 2. Add an interface interface working with a method teach() (5%) interface working void teach(String course) J 3. Modify Faculty class. (20%) a. a private data field and implement existing b. Modify Faculty class as a subclass of addition to the c. toString or print Info) method to...

  • This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and...

    This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and TweetManager. You will load a set of tweets from a local file into a List collection. You will perform some simple queries on this collection. The Tweet and the TweetManager classes must be in separate files and must not be in the Program.cs file. The Tweet Class The Tweet class consist of nine members that include two static ones (the members decorated with 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
ADVERTISEMENT