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

Mate you miss the road. This is not java but CPP pot. Get out....

What? I listed this in the C++ category.

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.

Yes you did

Oh. Sorry I did not mean to do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.