Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the question to the project...seeing if the coding works. I have it where it removes the item from tickets, but not removing it

This is the question to the project...seeing if the coding works. I have it where it removes the item from tickets, but not removing it from merchandise. Can you run this code in netbeans 8.2 to verify.

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 parks 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 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 on-order. 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. +Ticket (String, String, Date, double, boolean) +setPrice(double) +changePurchaseStatus(boolean) +getNumber() : long +getCategory() : String +getHolder() : String +getDate() : String +getPrice() : double +toString() : String 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. Create Apparel objects, at least two of each category, and add them to the AmusementPark. d. Set up a loop to: i. Display a short menu that allows a user to perform different actions in the gift shop such as looking up tickets or merchandise or purchasing items. Use all of the accessor methods in the AmusementPark to access specific items. Use the given methods to make purchases. ii. Prompt the user for a specific action. iii. Depending on the specific action prompt the user for additional input such as the id of a ticket or merchandise category, etc. You might want to use static methods in main() to handle each menu item separately. iv. Perform the action and display results such as the list of merchandise that the user has requested. Use the toString() method to display AmusementPark items on the screen. v. Prompt the user for continued access to the AmusementPark or to end the program. Your program should handle input errors gracefully. For example, if a particular ticket is searched and not found, the program should display a message such as "Selected ticket not found." Feel free to experiment with the tester program in order to develop a more useful program. Implementation Notes: 1) All accessor methods in AmusementPark must create a new ArrayList to copy objects into the new list. This requires loops to access objects from the corresponding instance fields and adding them to the new ArrayList. 2) Proper error handling is essential for this project. 3) Javadoc must be used to document AmusementPark, Ticket, and Merchandise. Submission Requirements: 1. Your project submission should have four files for this assignment: a. Ticket.java - The Ticket class, b. Merchandise.java - The Merchandise class, c. AmusementPark.java - The AmusementPark class, d. AmusementParkTester.java - A driver program for testing your AmusementPark class. 2. Remember to compile and run your program one last time before you submit it

AmusementPark File

package amusementpark;

import java.util.ArrayList; import java.util.Date; import java.util.NoSuchElementException;

public class AmusementPark {

/** Will store the ticket */ private ArrayList tickets;

/** Will store the Merchandise */ private ArrayList merchandise;

/** Park Name */ private String name;

/*** * * @param parkName */ AmusementPark(String parkName) { name = parkName; // Initialize the arraylist tickets = new ArrayList(); merchandise = new ArrayList(); }

/** * Add ticket * * @param ticket */ public void addTicket(Ticket ticket) { tickets.add(ticket); }

/*** * Add Merchandise * * @param m */ public void addMerchandise(Merchandise m) { merchandise.add(m); }

/** * * @param id */ public void buyMerchandise(String id) { boolean exp = true; for (int i = 0; i < merchandise.size(); i++) { long ID = merchandise.get(i).getId(); if (ID == Long.parseLong(id)) { // Remove merchandise.remove(i); exp = false; }

} if (exp == true) throw new NoSuchElementException("Id not found"); }

/*** * * @param id */ public void buyTicket(String id) { boolean exp = true;

for (int i = 0; i < tickets.size(); i++) { long ID = tickets.get(i).getNumber(); if (ID == Long.parseLong(id)) { // Remove tickets.remove(i); exp = false;

}

} if (exp == true) throw new NoSuchElementException("Id not found");

}

/** * @return the tickets */ public ArrayList getTickets() { ArrayList temp = new ArrayList(); if (tickets.size() == 0) return null; for (int i = 0; i < tickets.size(); i++) { temp.add(tickets.get(i)); }

return temp; }

/** * @return the merchandise */ public ArrayList getMerchandise() { ArrayList temp = new ArrayList(); if (merchandise.size() == 0) return null; for (int i = 0; i < merchandise.size(); i++) { temp.add(merchandise.get(i)); }

return temp; }

/** * @return the name */ public String getName() { return name; }

/*** * * @param id * @return */ public Merchandise getMerchandise(long id) { for (int i = 0; i < merchandise.size(); i++) { if (id == merchandise.get(i).getId()) { return merchandise.get(i); } } return null; }

/*** * * @param category * @return */ public Merchandise getMerchandise(String category) { for (int i = 0; i < merchandise.size(); i++) { if (category.equals(merchandise.get(i).getCategory())) { return merchandise.get(i); } } return null;

}

/*** * * @param id * @return */ public Ticket getTicket(long id) { for (int i = 0; i < tickets.size(); i++) { if (id == tickets.get(i).getNumber()) { return tickets.get(i); } } return null;

}

/*** * * @param date * @return */ public long getTickets(Date date) { for (int i = 0; i < tickets.size(); i++) { if (date.equals(tickets.get(i).getDate())) { return tickets.get(i).getNumber(); } } return -1; } }

AmusementParkTester File

package amusementpark;

import java.util.Date; import java.util.Scanner;

public class AmusementParkTester {

public static void main(String args[]) { AmusementPark amusementPark = new AmusementPark("Walden Amusement Park"); Ticket adult = new Ticket("123", "Adult", "Air USA", new Date(2015, 3, 12), 12322.4, true); Ticket child = new Ticket("10", "Children", "Air USA", new Date(2015, 3, 14), 13322.4, true); Ticket senior = new Ticket("20", "Senior", "Air USA", new Date(2015, 3, 20), 10000.4, true);

Merchandise merchandis1 = new Merchandise("123123", "sweatshirts", "Nike", 234, true); Merchandise merchandis2 = new Merchandise("12312323", "t-shirts", "Nike", 450, true);

// add it to Amuesement oark amusementPark.addTicket(adult); amusementPark.addTicket(child); amusementPark.addTicket(senior);

// Add merchandise amusementPark.addMerchandise(merchandis2); amusementPark.addMerchandise(merchandis2);

Scanner scanner = new Scanner(System.in); while (true) { System.out.println("1. Show Ticket Details: "); System.out.println("2. Merchandise Details: "); System.out.println("3. Remove Merchandise : "); System.out.println("4. Remove Tickets: "); System.out.println("Enter the choice: "); String chString = scanner.nextLine(); switch (Integer.parseInt(chString)) { case 1: System.out.print(" Enter the Ticket ID: "); int id = Integer.parseInt(scanner.nextLine()); System.out.println(amusementPark.getTicket(id).toString()); break; case 2: System.out.print(" Enter the Category: "); String cat = scanner.nextLine(); System.out .println(amusementPark.getMerchandise(cat).toString()); break;

case 3: System.out.print(" Enter the ID: "); String ID = scanner.nextLine(); amusementPark.buyTicket(ID); break;

case 4: System.out.print(" Enter the ID: "); ID = scanner.nextLine(); amusementPark.buyMerchandise(ID);

break;

}

System.out.println("Do you want to continue(Y/N)?: "); String choice = scanner.nextLine(); if (choice.charAt(0) == 'N') { System.exit(0); } }

}

}

Merchandise File

package amusementpark;

public class Merchandise { private long id; private String category; private String description; private double price; private boolean inStock;

/*** * * @param Id * @param c * @param d * @param p * @param stock */ Merchandise(String Id,String c, String d, double p, boolean stock){ id =Long.parseLong(Id); category =c; description =d; price=p; this.inStock =stock; } /** * @return the category */ public String getCategory() { return category; }

/** * @return the description */ public String getDescription() { return description; }

/** * @param price * the price to set */ public void setPrice(double price) { this.price = price; }

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

/** * @param inStock * the inStock to set */ public void setInStock(boolean inStock) { this.inStock = inStock; }

/** * @return the inStock */ public boolean getInstock() { return inStock; }

/** * @return the id */ public long getId() { return id; }

/*** * To String */ public String toString(){ return "Merchandise ID: "+id +" Category : "+category +" Description: "+description +" Price: "+price+"Instock ? : "+inStock+" "; } }

Ticket File

package amusementpark;

import java.util.Date;

public class Ticket { /** Ticket number */ private long number;

/** Category of Ticket */ private String category; /**Ticket Holder*/ private String holder;

/** Purchase date */ private Date date;

/** Ticket Price */ private double price;

private boolean status;

/*** * * @param num * @param cat * @param hold * @param d * @param p * @param newstatus */ Ticket (String num, String cat,String hold, Date d, double p, boolean newstatus){ number =Long.parseLong(num); category =cat; holder =hold; date =d; price=p; status =newstatus; } /** * @return the number */ public long getNumber() { return number; }

/** * @return the category */ public String getCategory() { return category; }

/** * @return the date */ public Date getDate() { return date; }

/** * @param price * the price to set */ public void setPrice(double price) { this.price = price; }

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

/*** * * @return */ public void changePurchaseStatus(boolean newStatus) { status= newStatus;

}

/*** * */ public String toString() { return "Ticket Number: "+number +" Category: "+category +" Holder: "+holder+" Date: "+date.toString()+" Price: "+price+" ";

}

/** * @return the holder */ public String getHolder() { return holder; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

Students also viewed these Databases questions

Question

List four or five important limitations of relevant cost analysis.

Answered: 1 week ago

Question

What is contained in a set of completed audit files?

Answered: 1 week ago

Question

=+2. Does your message present a conclusion?

Answered: 1 week ago