Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the class each room can be created like: LocationNode frontfoyer= new Loca

ID: 3697477 • Letter: U

Question

Using the class each room can be created like:

LocationNode frontfoyer= new LocationNode ("Front Foyer") ;

LocationNode livingRoom = newLocationNode ("Living Room") ;

etc.

After rooms are created they can be linked together:

frontfoyer.setEast(livingRoom);

livingRoom.setWest(frontFoyer);

etc.

Create a driver for the following LocationNode Class:

public class LocationNode {

private String description;
private LocationNode north, south, east, west;
   /**
   Constructor
   @param description= newDescription
    */
public LocationNode (String newDescription)
{
description = newDescription;

}
/**
   The getNorth method returns the node's north
   @return 'LocationNode with value from north field.
*/
public LocationNode getNorth()
{
return north;
}
   /**
       The setNorth method stores a value in the north field.
       @param this.north the value to store in north.
   */
public void setNorth(LocationNode north)
{
this.north = north;
}
   /**
       The getNorth method returns the nodees south
       @return 'LocationNode with value from south field.
*/

public LocationNode getSouth()
{
return south;
}
   /**
       The setSouth method stores a value in the South field.
       @param this.south the value to store in south.
   */
public void setSouth(LocationNode south)
{
this.south = south;
}
   /**
       The getEast method returns the nodees east
       @return 'LocationNode with value from east field.
*/
public LocationNode getEast()
{
return east;
}
   /**
       The setEast method stores a value in the East field.
       @param this.east the value to store in east.
   */
public void setEast(LocationNode east)
{
this.east = east;
}
   /**
       The getWest method returns the nodees west
       @return 'LocationNode with value from west field.
*/
public LocationNode getWest()
{
return west;
}
   /**
       The setWest method stores a value in the West field.
       @param this.west the value to store in west.
   */
public void setWest(LocationNode west)
{
this.west = west;
}
   /**
       The getDescription method returns the Strings description
       @return 'LocationNode' with value from description field.
*/
public String getDescription()
{
return description;
}
    /**
   * Generate a String representation of this LocationNode
   * a String representation of this LocatioNode
**/
public String toString() {
return description + " (" + north + ", " + south + ","+east+","+west+")";
}

}

Explanation / Answer

public class LocationNode {
   private String description;
   private LocationNode north, south, east, west;

   /**
   * Constructor
   *
   * @param description
   * = newDescription
   */
   public LocationNode(String newDescription) {
       description = newDescription;
   }

   /**
   * The getNorth method returns the node's north
   *
   * @return 'LocationNode with value from north field.
   */
   public LocationNode getNorth() {
       return north;
   }

   /**
   * The setNorth method stores a value in the north field.
   *
   * @param this.north the value to store in north.
   */
   public void setNorth(LocationNode north) {
       this.north = north;
   }

   /**
   * The getNorth method returns the nodees south
   *
   * @return 'LocationNode with value from south field.
   */
   public LocationNode getSouth() {
       return south;
   }

   /**
   * The setSouth method stores a value in the South field.
   *
   * @param this.south the value to store in south.
   */
   public void setSouth(LocationNode south) {
       this.south = south;
   }

   /**
   * The getEast method returns the nodees east
   *
   * @return 'LocationNode with value from east field.
   */
   public LocationNode getEast() {
       return east;
   }

   /**
   * The setEast method stores a value in the East field.
   *
   * @param this.east the value to store in east.
   */
   public void setEast(LocationNode east) {
       this.east = east;
   }

   /**
   * The getWest method returns the nodees west
   *
   * @return 'LocationNode with value from west field.
   */
   public LocationNode getWest() {
       return west;
   }

   /**
   * The setWest method stores a value in the West field.
   *
   * @param this.west the value to store in west.
   */
   public void setWest(LocationNode west) {
       this.west = west;
   }

   /**
   * The getDescription method returns the Strings description
   *
   * @return 'LocationNode' with value from description field.
   */
   public String getDescription() {
       return description;
   }

   /**
   * Generate a String representation of this LocationNode a String
   * representation of this LocatioNode
   **/
   public String toString() {
       return description + " (" + north.getDescription() + ", "
               + south.getDescription() + "," + east.getDescription() + ","
               + west.getDescription() + ")";
   }
}

/**
*
*/

/**
* @author srinu
*
*/
public class TestLocationNode {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       // creating objects
       LocationNode frontfoyer = new LocationNode("Front Foyer");
       LocationNode livingRoom = new LocationNode("Living Room");
       LocationNode kitchenRoom = new LocationNode("Kitchen Room");
       LocationNode playingRoom = new LocationNode("Playing Room");
       LocationNode sleepingRoom = new LocationNode("Sleeping Room");

       // setting the directions
       frontfoyer.setEast(sleepingRoom);
       frontfoyer.setNorth(playingRoom);
       frontfoyer.setSouth(kitchenRoom);
       frontfoyer.setWest(livingRoom);
       System.out.println(frontfoyer);

   }

}

OUTPUT:

Front Foyer (Playing Room, Kitchen Room,Sleeping Room,Living Room)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote