1

I have a school project entitled "Amusement Park Programming Project"

It requires four classes to be created:

  1. Ticket - Models admission tickets
  2. Merchandise - Models merchandise available in gift shop
  3. AmusementPark - Tracks ticket and merchandise inventory / sales
  4. WaldenAmusementPark - Tester program

AmusementPark Class is where I need help - I understand what needs to be happening per the instructions but I am unclear on how to access getter / setter methods and ArrayLists that are defined in Ticket and Merchandise to make things happen - I am reading the guidance, watching videos but unable to make it work?:

I've pasted my code (such as it is) below - any guidance is appreciated Not looking for the actual code to be written - just to clear up my confusion. Thanks in advance.

----------------TICKET CLASS----------------------------------

import java.util.*;

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


}  // End Brace Ticket Class

--------------------------MERCHANDISE CLASS------------------------------

public 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:" + "\t" + this.ID + "\n" + "Merchandise Category:" + "\t" + this.category + "\n" 
        + "\t" + "Merchandise Description:" + "\t" + this.description + "$" + this.price + "\t" 
        + "In-Stock Status" + "\t" + this.instock);
    }



} //End Brace Merchandise Class


------------------------AMUSEMENT PARK CLASS---------Where I Need Help!!--------
import java.util.ArrayList;

import java.util.Date;

public 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 
    private Date date;                          // Not called for in the instruction but I believe it is needed


    //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 getTicketDates(){        //Returns an ArrayList<Date> of all dates tickets are still available
        return                  
    } */

    // Need to fix this getTickets getter
/** public Date getTickets(){       // Returns an integer indicating number of tickets available for specified date
        return date;
    } */


    // Need to fix this getTicket getter
/** public long getTicket (long id){        //Returns Ticket number / ID that matches the specified ticket
        Ticket myTicketID = new Ticket();
            id.getnumber();
    }*/

//---------------------------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 getMerchandise(){                    //Returns an Arraylist<Merchandise> of all inventory - if no match return empty list
      return              ;
    } */

    //Need to fix this getMerchandise getter
/** public getMerchandise (String category){    //Returns a list of Merchandise objects whose category matches the specified (e.g., T-Shirts), no match return empty list
        return   
    }*/

    //Need to fix this getMerchandise getter
    /** public getMerchandise (long id){        //Returns the merchandise item that matches the specified id number, if not match return null
        return
    }*/

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



    //Need to fix this addTicket Mutator method
/** public addTicket (Ticket) { // Adds a new Ticket to the inventory of AmusementPark Class    
    } */

    //Need to fix this buyMerchandise Mutator method
/** public buyMerchandise (String id){ //Removes a Merchandise object from teh list of merchandise of the AmusementPark Class, if no match throw exception  
    } */


    //Need to fix this buyTicket Mutator method
/** public buyMerchandise (String id){ //Removes a Ticket object from the list of ticket items of the AmusementPark Class - If not match throw exception    
    } */






}  // End Brace AmusementPark Class

1 Answer 1

1

You need to instantiate a Ticket object where you need it.

Ticket yourTickecObject = new Ticket(constructor parameters);

And then just call the getter to get data

int price = yourTicketObject.getPrice(); 

And setter to set data

yourTicketObject.setPrice(someValue);

It's the same for ArrayList, Declaration in ticket:

ArrayList<someTipe> yourArrayListName = new ArrayList<someTipe>();

getter:

full Array list:

public ArrayList getYourArrayListName(){
  return this.yourArrayListName;
}

specific item:

public yourArrayListType getItem(index){
  return this.yourArrayListName.get(index)
}

setter:

If you want to add one item:

public void addObjectToYourArrayListName(SomeValidType argument){
   this.yourArrayListName.add(argument);
}

If you want to set the ArrayList:

public void setYourArrayListName(ArrayList<someValidType> argument){
   this.yourArrayListName = argument;
}

To access you Array List:

setter:

add an item:

yourTicketObject.addObjectToYourArrayListName(SomeValidType argument)

add a full ArrayList:

yourTicketObject.setYourArrayListName(ArrayList<someValidType>)

getter:

get full array list:

Arraylist<someType> someName = yourTicketObject.getYourArrayListName()

get specific index:

YourArrayListType variableName = yourTicketObject.getItem(index)

All this code is abstract you can use it every where adapted, pay attention to the types of variables.

Hope this helped

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - very grateful for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.