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

Amusement Park Programming Project - Java Project Outcomes 1. Use the Java selec

ID: 3582062 • Letter: A

Question

Amusement Park Programming Project - Java

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

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.

+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

* NOTE * This must be compiled as a project file and zipped. Netbeans IDE is used to create to the project file.

Explanation / Answer

import java.util.*;

class Ticket {

    //Ticket Class models admission tickets


    //Instance Variables called for in the instructions
    private long number;
    private String category;
    private String holder;
    private Date date;
    private double price;
    private boolean purchased;


    // Constructor Ticket -- The instructions did not call for instance field "number" as a parameter and left "purchased" out of the UML???
    public Ticket (long number, String category, String holder, Date date, double price, boolean purchased){    
        this.number = number;               //Stores unique ticket ID Number
        this.category = category;           //Stores adult, child, or senior
        this.holder = holder;               //Stores name of purchaser
        this.date = date;                   //Stores admission date for the ticket
        this.price = price;                 //Stores price of the ticket
        this.purchased = purchased;         //Stores true if purchased, false if reserved
    } // End Brace Constructor Ticket


    // MUTATOR METHODS..............................................

    // setPrice Mutator Method
    public void setPrice(double price){
        this.price = price;
    } // End Brace setPrice

    //changePurchaseStatus Mutator Method
    public void setchangePurchaseStatus(boolean newStatus){
        this.purchased = newStatus;
    } // End Brace changePurchasedStatus

    // ACCESSOR METHODS.............................................

    //getnumber Accessor Method
    public long getnumber(){
        return number;
    }

    //getcategory Accessor Method
    public String getcategory(){
        return category;
    }

    //getholder Accessor Method
    public String getholder(){
        return holder;
    }

    //getdate Accessor Method
    public Date getdate(){
        return date;
    }

    //getprice Accessor Method
    public double getprice(){
        return price;
    }

    //getpurchased Accessor Method
    public boolean getpurchased(){
        return purchased;
    }
  
    // toString Method.............................................
    @Override
    public String toString(){
        return(" Ticket number:" + " " + this.number + " " + "Ticket Category:" + " " + this.category + " "
         + "Ticket Holder:" + " " + this.holder + " " + "Date:" + " " + this.date + " " +" Ticket Purchased:"+" "+this.purchased);
    }


} // End Brace Ticket Class


class Merchandise {


    //Instance Variables called for in the instructions
    private long ID;                            //ID of specific merchandise item
    private String category;                    //Stores type of item (T-Shirt, Sweatshirt, Stuffed Animal) - if invalid display "Unknown"
    private String description;                 //Stores description of item
    private double price;                       //Stores price of item
    private boolean instock;                    //True = in stock False = on order


    // Constructor Merchandise
    public Merchandise(long ID, String category, String description, double price, boolean instock){
         this.ID = ID;
         this.category = category;
         this.description = description;
         this.price = price;
         this.instock = instock;
    } // End Brace Constructor Merchandise

    // MUTATOR METHODS..............................................

    public void setPrice(double price){
        this.price = price;
    }

    public void setInstock(boolean newStatus){
        this.instock = newStatus;
    }

    // ACCESSOR METHODS.............................................

    public long getID(){
        return ID;
    }

    public String getcategory(){
        return category;
    }

    public String getdescription(){
        return description;
    }

    public double getprice(){
        return price;
    }

    public boolean getinstock(){
        return instock;
    }


    // toString Method.............................................
    @Override
    public String toString(){
        return("Merchandise ID:" + " " + this.ID + " " + "Merchandise Category:" + " " + this.category + " "
        + " " + "Merchandise Description:" + " " + this.description + "$" + this.price + " "
        + "In-Stock Status" + " " + this.instock);
    }

} //End Brace Merchandise Class


class AmusementPark {

    //Instance Variables called for in the instructions
    private String name = "Walden Gift Shop";   // Assigned a value that I think is needed to support "getName" Accessor Method

    //ArrayLists
    public static ArrayList<Ticket> tickets = new ArrayList<Ticket>();                  //Stores ticket objects
    public static ArrayList<Merchandise> merchandise = new ArrayList<Merchandise>();    //Stores Merchandise objects

    // Stores ArrayList of type Date called "ticketDate" that has all dates for which tickets are still available
    // This ArrayList was not clearly called for in the instructions but is required to return dates for which tickets are still available -
    // if no tickets are available return empty list
/** public ArrayList<Date> ticketDate(){
    ArrayList<Date> ticketDate = new ArrayList<Date>();
    Date.(2014, 03, 01);
    } */

    // Constructor AmusementPark
    public AmusementPark(String name){ //How should I be referencing / using the ArrayLists tickets & merchandise in the constructor??????
        this.name = name;
    }


    // ACCESSOR METHODS.............................................

    public String getName(){        // Returns the name of the amusement park shop
        return name;
    }

//--------------------- Have 3 getters to return various Ticket data - Need to fix the stubs for them shown below----------------------

    // Need to fix this getTicketDates getter
public ArrayList<Date> getTicketDates(){        //Returns an ArrayList<Date> of all dates tickets are still available
       ArrayList<Date> dates=new ArrayList<Date>();
       for(Ticket item:tickets)
       {
           dates.add(item.getdate());
       }
       return dates;
    }

    // Need to fix this getTickets getter
public int getTickets(Date d){       // Returns an integer indicating number of tickets available for specified date
        int count=0;
        for(Ticket item:tickets)
       {
           if(d==item.getdate())
           count++;
       }
       return count;
    }


    // Need to fix this getTicket getter
public Ticket getTicket (long id){        //Returns Ticket number / ID that matches the specified ticket
       for(Ticket item:tickets)
       {
           if(item.getnumber()==id)
           return item;
       }
    return   null;
    }

//---------------------------END the 3 "getMerchandise" getters----------------------------------------------------------------------

//--------------------- Have 3 "getMerchandise" getters to define - Need to fix the stubs for them shown below----------------------

    // Need to fix this getMerchandise getter
public ArrayList<Merchandise> getMerchandise(){                    //Returns an Arraylist<Merchandise> of all inventory - if no match return empty list
   ArrayList<Merchandise> merchandiseList=merchandise;
   return   merchandiseList;
    }

    //Need to fix this getMerchandise getter
public ArrayList<Merchandise> getMerchandise (String category){    //Returns a list of Merchandise objects whose category matches the specified (e.g., T-Shirts), no match return empty list
ArrayList<Merchandise> merchandiseList=new ArrayList<Merchandise>();
         for(Merchandise item: merchandise)
    {
        if(item.getcategory().equals(category))
        merchandiseList.add(item);
    }
    return   merchandiseList;
    }

    //Need to fix this getMerchandise getter
public Merchandise getMerchandise (long id){        //Returns the merchandise item that matches the specified id number, if not match return null
         for(Merchandise item: merchandise)
    {
        if(item.getID()==id)
        return item;
    }
    return null;
    }

//---------------------------END the 3 "getMerchandise" getters----------------------------------------------------------------------

    //Need to fix this addTicket Mutator method
public void addTicket (Ticket t) { // Adds a new Ticket to the inventory of AmusementPark Class  
tickets.add(t);
    }

//Need to fix this buyMerchandise Mutator method
public void addMerchandise (Merchandise m){ //adds a Merchandise object from teh list of merchandise of the AmusementPark Class, if no match throw exception
merchandise.add(m);
    }
    //Need to fix this buyMerchandise Mutator method
public void buyMerchandise (long id) throws Exception{ //Removes a Merchandise object from teh list of merchandise of the AmusementPark Class, if no match throw exception
boolean found=false;
int index=-1;
for(int i=0;i<merchandise.size();i++)
    {
        if(merchandise.get(i).getID()==id)
        {
            found=true;
            index=i;
      
        }
    }
    if(!found)
    {
        throw new Exception("Selected merchandise not found");
    }
    else
    merchandise.remove(index);

    }


    //Need to fix this buyTicket Mutator method
public void buyTicket (long id)throws Exception{ //Removes a Ticket object from the list of ticket items of the AmusementPark Class - If not match throw exception  
   boolean found=false;
int index=-1;
for(int i=0;i<tickets.size();i++)
    {
        if(tickets.get(i).getnumber()==id)
        {
            found=true;
            index=i;
      
        }
    }
    if(!found)
    {
        throw new Exception("Selected merchandise not found");
    }
    else
    tickets.remove(index);
} // End Brace AmusementPark Class

//driver class
public class HelloWorld
{
      static AmusementPark park=new AmusementPark ("Walden Amusement Park");
        static ArrayList<Ticket> bookstore=new ArrayList<Ticket>();
              static   Scanner input=new Scanner(System.in);
    public static void displayTickets()
    {
        for(Ticket item:park.tickets)
        System.out.println(item);
    }
  
    public static void displayMerchandise()
    {
        for(Merchandise item:park.getMerchandise())
        System.out.println(item);
    }
  
    public static void addTicket()
    {
        Ticket t=new Ticket(123,"Horror","Jack",new Date("1/1/1"),1234,true);
        park.addTicket(t);
    }
  
    public static void addMerchandise()
    {
        Merchandise t=new Merchandise(1,"T-Shirt","woollen shirts",1234,true);
        park.addMerchandise(t);
    }
  
    public static void buyTicket() throws Exception
    {
        try
        {
            System.out.print("Enter ticket id: ");
            park.buyTicket(input.nextLong());
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
  
    public static void buyMerchandise() throws Exception
    {
        try
        {
             System.out.print("Enter merchandise id: ");
            park.buyMerchandise(input.nextLong());
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
  
    public static void main(String args[]) throws Exception
    {
     
        bookstore.add(new Ticket(12345,"Horror","Jack",new Date("12/12/12"),1234,true));
        bookstore.add(new Ticket(212121,"Romance","Laura",new Date("1/1/1"),2121,false));
        bookstore.add(new Ticket(67890,"Drama","Jill",new Date("12/12/12"),678,true));
        park.tickets=bookstore;
        ArrayList<Merchandise> apparel=new ArrayList<Merchandise>();
        apparel.add(new Merchandise(1234,"T-Shirt","woollen shirts",1234,true));
        apparel.add(new Merchandise(2121,"T-Shirt","nylon shirts",678,true));
        apparel.add(new Merchandise(2345,"SweatShirt","god",345,false));
        apparel.add(new Merchandise(890,"SweatShirt","cartoon",90,true));
        apparel.add(new Merchandise(5678,"Stuffed animal","barbie",234,false));
        apparel.add(new Merchandise(456,"Stuffed animal","teddy bear",100,true));
        park.merchandise=apparel;
        boolean flag=true;
        int choice;
    do
        {
            System.out.println("**************************************");
            System.out.println(" 1-display Merchandise 2-Display Tickets 3-Add Ticket 4-Add Merchandise 5-Buy Ticket 6-Buy Merchandise");
            System.out.println("Enter your choice: ");
            choice=input.nextInt();
            switch(choice)
            {
                case 1:displayTickets();break;
                case 2:displayMerchandise();break;
                case 3:addTicket();break;
                case 4:addMerchandise();break;
                case 5:buyTicket();break;
                case 6:buyMerchandise();break;
                default: flag=false;break;
            }
             System.out.println("**************************************");
        }while(flag);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote