Programming Project 2: Amusement Park Programming Project Programming Project 2
ID: 3853573 • Letter: P
Question
Programming Project 2: Amusement Park Programming Project Programming Project 2 provides you with the opportunity to apply all of the concepts covered throughout this course to create a program that implements an amusement park information system that keeps track of admission tickets and merchandise in the gift shop. Download the Amusement Park Programming Project document (located in this week’s Learning Resources) and carefully review the requirements. You will then create a new project in NetBeans to implement this programming project. Your completed project is due by Day 7 of Week 8. Submit your project by creating a zip archive of your project’s NetBeans project folder and submitting the zip archive. Use the following rubric to estimate your grade on the assignment: Rubric for Programming Project 2 Amusement Park Programming Project Project Outcomes 1. Use the Java selection constructs (if and if else). 2. Use the Java iteration constructs (while, do, for). 3. Use Boolean variables and expressions to control iterations. 4. Use arrays or ArrayList for storing objects. 5. 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 class to model gift shop merchandise, the amusement park, and the amusement park tester. The gift shop supports access to specific merchandise in the park’s gift shop and to purchase the merchandise or to order new merchandise for the gift shop. The UML diagram for each class (except the tester class) is given below. 1) Develop a simple class that models admission tickets. Each admission is described by several instance fields: a. A ticket number as a long integer to identify the unique ticket, b. A ticket category represented as a String to store the category of the ticket (i.e. adult, child, senior), c. A ticket holder represented as a String to store the name of the person who purchased the ticket, d. A date represented as a Date to store the admission date for the ticket, e. A price represented as a double to store the price of the ticket, f. A purchase status represented as a boolean to indicate if the ticket has been purchased (or is reserved). Ticket -number : long -category : String -holder : String -date : Date -price : double +Ticket (String, String, Date, double, boolean) +setPrice(double) +changePurchaseStatus(boolean) +getNumber() : long +getCategory() : String +getHolder() : String +getDate() : String +getPrice() : double +toString() : String In addition to these fields, the class has the following constructors and methods: a. A parameterized constructor that initializes the attributes of a ticket. b. setPrice(double price) to change the price of a textbook. c. changePurchaseStatus(boolean newStatus) to change the purchase status of the ticket. d. Accessor methods for all instance fields. e. toString() to return a neatly formatted string that contains all the information stored in the instance fields. 2) Develop a simple class that models merchandise available in the gift shop such as t-shirts, sweatshirts, and stuffed animals. The class has several instance fields: a. An ID as a long integer to identify the specific merchandise item, b. A category as a String to store the specific type of merchandise, c. A description as a String to store the description of the merchandise, d. A price represented as a double to store the price of the merchandise, e. An instock as a boolean to indicate if the merchandise is instock or onorder. Valid values for category include "T-Shirt", "Sweatshirt", and "Stuffed Animal", as well as any additional category you choose to support. If invalid values are entered, an error message must be printed and the category instance field must be set to "UNKNOWN". In addition to these attributes, the class has the following constructors and methods: f. A parameterized constructor that initializes the attributes of a merchandise item. g. setPrice(double price) to change the price of the merchandise. h. setInstock(boolean newStatus) to change the status of the merchandise item. i. Accessor methods for all instance fields. j. toString() to return a neatly formatted string that contains all the information stored in the instance fields. Merchandise -id : long -category : String -description : String -price : double -inStock : boolean +Merchandise(String, String, String, double, boolean) +setPrice(double) +setInstock(boolean) +getId() : String +getCategory() : String +getDescription() : String +getPrice() : double +getInstock() : boolean +toString() : String 3) Develop class AmusementPark that keeps track of tickets and gift shop inventory. The AmusementPark uses two ArrayLists to store Ticket and Merchandise objects. The AmusementPark provides several methods to add merchandise to the gift shop and to access merchandise. The following UML diagram describes the class, the constructor, and the methods: AmusementPark -tickets : ArrayList -merchandise : ArrayList -name : String +AmusementPark(String) +getName() : String +getTicketDates() : ArrayList +getTickets(Date date) : int +getTicket(long id) : Ticket +getMerchandise() : ArrayList +getMerchandise(String category) : ArrayList +getMerchandise(long id) : Merchandise +addTicket(Ticket) +addMerchandise(Merchandise) +buyMerchandise(String id) +buyTicket(String id) a. The class has three instance fields: a. name, the name of the bookstore b. tickets, an ArrayList storing Ticket objects c. merchandise, an ArrayList storing Merchandise objects b. getName() returns the name of the bookstore. c. getTicketDates() returns an ArrayList of all the dates for which tickets are still available. If there are no tickets available, an empty list is returned. d. getTickets (Date date) returns an integer indicating the number of tickets available for the specified date. e. getTicket(long id) returns the Ticket that matches the specified id. If there is no Ticket matching the given id, null is returned. f. getMerchandise()returns an ArrayList of all the inventory (in-stock and ordered). This method must create a separate copy of the ArrayList before it returns the list. If there are no merchandise items in the AmusementPark, an empty list is returned. g. getMerchandise(String category) returns a list of Merchandise objects whose category matches the specified category. For example, if called with "T-shirt" the method returns all Merchandise objects with the category "T-shirt" as a new list. This method must create a new copy of an ArrayList that stores all the matched Merchandise objects. If no items in the AmusementPark match the given name, an empty list is returned. h. getMerchandise(long id) returns the merchandise item that matches the specified id. If there is no merchandise item matching the given id, null is returned. i. addTicket(Ticket) adds a new Ticket to the inventory of the AmusementPark. j. addMerchandise(Merchandise) adds a new Merchandise to the inventory of the AmusementPark. k. buyMerchandise(String id) removes a Merchandise object from the list of merchandise of the AmusementPark. If the id does not match any Merchandise object in the list, an exception is thrown. l. buyTicket(String id) removes a Ticket object from the list of ticket items of the AmusementPark. If the id does not match any Ticket object in the list, an exception is thrown. 4) Design a tester class called AmusementParkTester. The tester class has a main() method and tests the functionality of the class AmusementPark as follows: a. Create AmusementPark and name it "Walden Amusement Park". b. Create a minimum of three Ticket objects and add them to the bookstore. c. merchandise, an ArrayList storing Merchandise objects b. getName() returns the name of the bookstore. c. getTicketDates() returns an ArrayList of all the dates for which tickets are still available. If there are no tickets available, an empty list is returned. d. getTickets (Date date) returns an integer indicating the number of tickets available for the specified date. e. getTicket(long id) returns the Ticket that matches the specified id. If there is no Ticket matching the given id, null is returned. f. getMerchandise()returns an ArrayList of all the inventory (in-stock and ordered). This method must create a separate copy of the ArrayList before it returns the list. If there are no merchandise items in the AmusementPark, an empty list is returned. g. getMerchandise(String category) returns a list of Merchandise objects whose category matches the specified category. For example, if called with "T-shirt" the method returns all Merchandise objects with the category "T-shirt" as a new list. This method must create a new copy of an ArrayList that stores all the matched Merchandise objects. If no items in the AmusementPark match the given name, an empty list is returned. h. getMerchandise(long id) returns the merchandise item that matches the specified id. If there is no merchandise item matching the given id, null is returned. i. addTicket(Ticket) adds a new Ticket to the inventory of the AmusementPark. j. addMerchandise(Merchandise) adds a new Merchandise to the inventory of the AmusementPark. k. buyMerchandise(String id) removes a Merchandise object from the list of merchandise of the AmusementPark. If the id does not match any Merchandise object in the list, an exception is thrown. l. buyTicket(String id) removes a Ticket object from the list of ticket items of the AmusementPark. If the id does not match any Ticket object in the list, an exception is thrown. 4) Design a tester class called AmusementParkTester. The tester class has a main() method and tests the functionality of the class AmusementPark as follows: a. Create AmusementPark and name it "Walden Amusement Park". b. Create a minimum of three Ticket objects and add them to the bookstore.
Explanation / Answer
Find the program below.
Admission.java
package com.chegg.serial;
import java.util.Date;
public class Admission {
private long ticketNo;
private String catagory;
private String tcktHldrName;
private Date admissionDate;
private double price;
private boolean status;
/**
* @param ticketNo
* @param catagory
* @param tcktHldrName
* @param admissionDate
* @param price
* @param status
*/
public Admission(long ticketNo, String catagory, String tcktHldrName, Date admissionDate, double price,
boolean status) {
super();
this.ticketNo = ticketNo;
this.catagory = catagory;
this.tcktHldrName = tcktHldrName;
this.admissionDate = admissionDate;
this.price = price;
this.status = status;
}
/**
* @return the ticketNo
*/
public long getTicketNo() {
return ticketNo;
}
/**
* @param ticketNo the ticketNo to set
*/
public void setTicketNo(long ticketNo) {
this.ticketNo = ticketNo;
}
/**
* @return the catagory
*/
public String getCatagory() {
return catagory;
}
/**
* @param catagory the catagory to set
*/
public void setCatagory(String catagory) {
this.catagory = catagory;
}
/**
* @return the tcktHldrName
*/
public String getTcktHldrName() {
return tcktHldrName;
}
/**
* @param tcktHldrName the tcktHldrName to set
*/
public void setTcktHldrName(String tcktHldrName) {
this.tcktHldrName = tcktHldrName;
}
/**
* @return the admissionDate
*/
public Date getAdmissionDate() {
return admissionDate;
}
/**
* @param admissionDate the admissionDate to set
*/
public void setAdmissionDate(Date admissionDate) {
this.admissionDate = admissionDate;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(double price) {
this.price = price;
}
/**
* @return the status
*/
public boolean isStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(boolean status) {
this.status = status;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "[" + ticketNo + ", " + catagory + ", " + tcktHldrName + ", " + admissionDate + ", " + price + ", "
+ status + "]";
}
}
Merchandise.java
package com.chegg.serial;
public class Merchandise {
private long id;
private String catagory;
private String description;
private double price;
private boolean instock;
/**
* @param id
* @param catagory
* @param description
* @param price
* @param instock
*/
public Merchandise(long id, String catagory, String description, double price, boolean instock) {
super();
this.id = id;
this.catagory = catagory;
this.description = description;
this.price = price;
this.instock = instock;
}
/**
* @return the id
*/
public long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* @return the catagory
*/
public String getCatagory() {
return catagory;
}
/**
* @param catagory the catagory to set
*/
public void setCatagory(String catagory) {
this.catagory = catagory;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "[" + id + ", " + catagory + ", " + description + ", " + price + ", " + instock + "]";
}
/**
* @param price the price to set
*/
public void setPrice(double price) {
this.price = price;
}
/**
* @return the instock
*/
public boolean isInstock() {
return instock;
}
/**
* @param instock the instock to set
*/
public void setInstock(boolean instock) {
this.instock = instock;
}
}
AmusementPark.java
package com.chegg.serial;
public class AmusementPark {
private List<Admission> ticketList;
private List<Merchandise> merchandiseList;
/**
* @return the ticketList
*/
public List<Admission> getTicketList() {
return ticketList;
}
/**
* @param ticketList the ticketList to set
*/
public void setTicketList(List<Admission> ticketList) {
this.ticketList = ticketList;
}
/**
* @return the merchandiseList
*/
public List<Merchandise> getMerchandiseList() {
return merchandiseList;
}
/**
* @param merchandiseList the merchandiseList to set
*/
public void setMerchandiseList(List<Merchandise> merchandiseList) {
this.merchandiseList = merchandiseList;
}
}
AmusementTester.java
package com.chegg.serial;
import java.util.ArrayList;
import java.util.Date;
public class AmusementTester {
public static void main(){
AmusementPark obj = new AmusementPark();
Admission a = new Admission(41, "catagory", "tcktHldrName", new Date(), 453.2, true);
Admission b = new Admission(42, "catagory", "tcktHldrName", new Date(), 74.5, true);
ArrayList<Admission> ticketList = new ArrayList<Admission>();
ticketList.add(a);
ticketList.add(b);
obj.setTicketList((List<Admission>) ticketList);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.