Cohesion of methods and classes (Eat class)...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    Cohesion of methods and classes (Eat class)...

    [CODE=JAVA]

    import java.util.Set;
    import java.util.HashM ap;
    import java.util.Itera tor;

    /**
    * @3rd Annual Bahamas Pelletier School Food-a-thon and Gaming Session
    * @programmer Dököll
    * @version 2007.12.9
    */

    public class Eat
    {
    private String description;
    private HashMap<String, Eat> exits; // stores exits of this treat.


    public Eat(String description)
    {
    this.descriptio n = description;
    exits = new HashMap<String, Eat>();
    }


    public void setExit(String direction, Eat neighbor)
    {
    exits.put(direc tion, neighbor);
    }


    public String getShortDescrip tion()
    {
    return description;
    }


    public String getLongDescript ion()
    {
    return "4: You have just eaten " + description + ".\n" + getExitString() ;
    }

    private String getExitString()
    {
    String returnString = "Exit:";
    Set<String> keys = exits.keySet();
    for(String exit : keys) {
    returnString += " " + exit;
    }
    return returnString;
    }

    public Eat getExit(String direction)
    {
    return exits.get(direc tion);
    }
    }

    [/CODE]

    End of session...

    Please fire this up and have fun. Comment if you need to. My fist real one, so I expect some healthy criticism:-)

    Thanks!

    Dököll
Working...