Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to call a method in another class

807591Mar 7 2008 — edited Mar 7 2008
My Game class:
private void goRoom(Command command) 
    {
        if(!command.hasSecondWord())
        {
            // if there is no second word, we don't know where to go...
            System.out.println("Go where?");
            return;
        }

        String direction = command.getSecondWord();

        // Try to leave current room.
        Room nextRoom = currentRoom.nextRoom(direction);

        if (nextRoom == null)
            System.out.println("There is no door!");
            
        else
        
            if(nextRoom.isLocked() == true)      <-----------------------I want that to call Item class, as isLocked accessor is in there
            System.out.println("You need a key to enter this room.");
Item Class:
public class Item
{
    // instance variables - replace the example below with your own
    private String description;
    private int weight;
    private boolean isLocked;

    /**
     * Constructor for objects of class Item
     */
    public Item(String description)
    {
        this.description = description;
        weight = 0;
    }

    public Item(String description, int weight, boolean isLocked)
    {
        this.description = description;
        this.weight = weight;
        this.isLocked = isLocked;
    }
    
    public boolean isLocked()
    {
        return isLocked;    <------------------This is waht im tryin to get the code on the top to call
    }
What is the correct syntax to do this?
Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2008
Added on Mar 7 2008
20 comments
199 views