Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with how to implement this class? (Visit method inherited in BoundsMapper) The code for Room is : import java.io.Serializable; import java.util.Collections; import

Please help me with how to implement this class?

(Visit method inherited in BoundsMapper)

image text in transcribedimage text in transcribedThe code for Room is :

import java.io.Serializable; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; /**  * Building block for the map. Contains {@link Thing Thing}s Note: all exit labels are case sensitive.  *   */ public class Room implements Serializable { // Description for this Room private String description; // Exits from this Room. Strings are names of the exits private Map exits; // Things in this Room private List contents; /* * Replace characters in description strings * It is very important that this is private so it will be resolved * correctly during construction */ private void replaceDescription(String description) { this.description = description.replace(' ', '*') .replace(' ', '*'); } /**  * @param description Description for the room Note: each  * in description will be replaced with a `*`.  */  public Room(String description) { replaceDescription(description); exits = new TreeMap(); contents = new LinkedList(); } /**  * A description of the room.  *  * @return Description  */  public String getDescription() { return description; } /**  * Change Room description Note: each or in the new  * description will be replaced with a `*`.  *  * @param description new Description  */  public void setDescription(String description) { replaceDescription(description); } /**  * What exits are there from this Room?  *  * @return Non-modifiable map of names to Rooms  */  public Map getExits() { return Collections.unmodifiableMap(this.exits); } /**  * What Things are in this Room?  *  * @return Non-modifiable List of Things in the Room  */  public List getContents() { return Collections.unmodifiableList(this.contents); } /**  * Add a new exit to this Room.  *  * @param name Name of the exit  * @param target Room the exit goes to  * @throws ExitExistsException if the room already has an exit of that name  * @throws NullRoomException if target is null  */  public void addExit(String name, Room target) throws ExitExistsException, NullRoomException { if (exits.containsKey(name)) { throw new ExitExistsException(); } if (target == null) { throw new NullRoomException(); } exits.put(name, target); } /**  * Remove an exit from this Room Note: silently fails if exit does not  * exist.  *  * @param name Name of exit to remove  */  public void removeExit(String name) { exits.remove(name); } /**  * Add Thing to this Room.  *  * @param item Thing to add  */  public void enter(Thing item) { if (!contents.contains(item)) { contents.add(item); } } /**  * Remove item from Room. Note: will fail if item is not in the Room or if  * something wants to fight item.  *  * @param item Thing to remove  * @return true if removal was successful  */  public boolean leave(Thing item) { if (!contents.contains(item)) { return false; } boolean trap = false; if (item instanceof Mob) { for (Thing i : contents) { if ((i instanceof Mob) && (i != item)) { if (((Mob) i).wantsToFight((Mob) item)) { trap = true; break; } } } } if (trap) { return false; } contents.remove(item); return true; } /**  * Connects two rooms both ways. Note: either both exits are created or  * neither are.  *  * @param room1 First room  * @param room2 Second room  * @param label1 Name of exit which goes from room1 to room2  * @param label2 Name of exit which goes from room2 to room1  * @throws ExitExistsException if one or more of the exits are in use  * @throws NullRoomException if either room1 or room2 is null  * @throws NullPointerException if either label is null  */  public static void makeExitPair(Room room1, Room room2, String label1, String label2) throws ExitExistsException, NullRoomException { } }
Class MapWalker java.lang.Object MapWalker Direct Known Subclasses: BoundsMapper public class MapWalker extends java.lang.Object Iterator over all reachable Rooms Constructor Summary Constructors Constructor and Description MapWalker (Room start) Call the visitO method on all reachable Rooms. Method Summary Instance Methods Concrete Methods All Methods Modifier and Type boolearn protected void Method and Description hasvisited (Room room) reset () Called by walkclears any state from previous walks. visit (Room room) process a room override to customise behaviour walk () Visit all reachable rooms and call visit0. protected void void Methods inherited from class java.lang.Object clone, equals, finalize, getclass, hashCode, notify, notifyAll, toString, wait, wait, wait Class MapWalker java.lang.Object MapWalker Direct Known Subclasses: BoundsMapper public class MapWalker extends java.lang.Object Iterator over all reachable Rooms Constructor Summary Constructors Constructor and Description MapWalker (Room start) Call the visitO method on all reachable Rooms. Method Summary Instance Methods Concrete Methods All Methods Modifier and Type boolearn protected void Method and Description hasvisited (Room room) reset () Called by walkclears any state from previous walks. visit (Room room) process a room override to customise behaviour walk () Visit all reachable rooms and call visit0. protected void void Methods inherited from class java.lang.Object clone, equals, finalize, getclass, hashCode, notify, notifyAll, toString, wait, wait, wait

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

Find io in the op amp circuit of Fig. 5.66? 50 kS 04 V

Answered: 1 week ago

Question

2. Is this illegal harassment/discrimination?

Answered: 1 week ago

Question

Advance warning and an explanation for the layoff.

Answered: 1 week ago