I am trying to create a player class to pick up and drop as well as carry items and this is the code I have so far. However, I am unsure what needs to be changed for it to work.

import java.util.ArrayList;


public class Player
    {
        private String Name_;
        private ArrayList<Item> playerItems_;


        /**Construtor for Player class
         *@param Name - Name of the player
         */
        public Player(String name)
        {
            Name_ = name;
            playerItems_ = new ArrayList<Item>();
        }

        /**Accesor Method for the pkayer name
         *
         */
        public String getName()
        {
            return Name_;
        }

        /**
         * Add an item the player item storage
         * @param Item item - the item that the payer will pick up
         */
        public void pickUpItem(Item item)
        {
            if(!item.gotIt()) playerItems_.add(item);
            item.pickUpItem();
        }
        /**
         * Remove an item the player item storage
         * @param Item item - the item that the payer will drop
         */
        public void dropItem(String itemName)
        {
            for(int i = 0; i < playerItems_.size();i++)
            {
                if(playerItems_.get(i).getName().equalsIgnoreCase(itemName))
                {
                    playerItems_.remove(i);
                    break;
                }
            }
        }

        /**
         *Determines wheter the player has this item or now
         *@param String itemNAme
        */
        public boolean contains(String itemName)
        {
            for(Item item : playerItems_)
            {
                if(item.getName().equalsIgnoreCase(itemName))return true;  
            }
            return false;
        }

    }//Class

Edited 3 Years Ago by deceptikon: Moved to Java

I listed this in the C++ category.

To clarify, did you intend to do that? If not, I'll move the thread. If so, please explain how this thread is relevant to C++ since the code you posted is clearly Java.

This question has already been answered. Start a new discussion instead.