recently, i bought a textbook call "Objects first with java" for self study. at the chapter 7, design a "Command Line Game" and a exercise ask me to put more functions in the game, as i do so i encounter many problems, and one of the problem as sohowing below, i wonder if anybody can help me

when i add these two codes :

Item textbook = new Item("this is a Java textbook",5);
office.addItem("Textbook",textbook);

the complier tell me:
Cannot resolve symbol constructor Item (java.jang.string,int)

can somebody please tell me what wrong with it thank you very much
---------------------------------------------------------------------------

public class Game 
{
    private Parser parser;
    private Room currentRoom;
    private Player currentPlayer;
   
   
        
    /**
     * Create the game and initialise its internal map.
     */
    public Game() 
    {
        createRooms();
        parser = new Parser();
        
        currentPlayer = new Player("Mark",currentRoom);
    }

    /**
     * Create all the rooms and link their exits together.
     */
    private void createRooms()
    {
        Room outside, theatre, pub, lab, office, cellar;
      
        // create the rooms
        outside = new Room("outside the main entrance of the Polytechnic");
        theatre = new Room("in a lecture theatre");
        pub = new Room("in the campus pub");
        lab = new Room("in a computing lab");
        office = new Room("in the computing admin office");
        cellar = new Room("in the cellar");
        // initialise room exits
        outside.setExit("east", theatre);
        outside.setExit("south", lab);
        outside.setExit("west", pub);

        theatre.setExit("west", outside);

        pub.setExit("east", outside);

        lab.setExit("north", outside);
        lab.setExit("east", office);
        

        office.setExit("west", lab);
        office.setExit("down", cellar);
        cellar.setExit("up", office);
        currentRoom = outside;  // start game outside
        
        // add items 
        Item textbook = new Item("this is a Java textbook",5);
        office.addItem("Textbook",textbook);
    }

[I]some other methods omitted [/I]

Code tags added. -Narue
-------------------------------------------------------------------------

Where is your Item class?

sorry i am just new and i am not sure what might make a good post

item class
-----------------------------------------------

import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;


public class Item
{
    private String description;
    private String name;
    private int weight;
    private boolean moveable;


    /**
     * Constructor for objects of class Item.
     */
    public Item(String myDescription, String myName, int myWeight, boolean itemMoveable) 
    {
        this.description = myDescription;
        this.name = myName;
        this.weight = myWeight;
        this.moveable = itemMoveable;       
    }

    /**
     * Return the description of the item (the one that was defined
     * in the constructor).
     */
    public String getDescription()
    {
        return description;
    }
    
    /**
     * Return the name of the item (the one that was defined
     * in the constructor).
     */
    public String getName()
    {
        return name;
    }
    
    public boolean isMoveable()
    {
        return (moveable == false);
    }
    
    /**
     * Return the weight of the item 
     */
    public int getWeight()
    {
        return weight;
    }
    
}

Code tags added. -Narue

Well, you don't have a constructor matching the parameter list you're using when you try to create an Item.
That's why you get that error, the compiler cannot find a symbol (meaning a reference to something) with the required signature in the Item class.

in the Item class constructor, you have
public Item(String myDescription, String myName, int myWeight, boolean itemMoveable)
... you're asking for 2 Strings, an int, and a boolean... but then when you construct the Item in the game code, you are only sending it one String, and an int.. they both need to match.

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.