Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete Exercise 6e: 8.4 . Create a map of your game scenario in any common electronic format (such as .pdf, .doc, .pptx, .jpg, etc.). Update

  1. Complete Exercise 6e: 8.4 .
    • Create a map of your game scenario in any common electronic format (such as .pdf, .doc, .pptx, .jpg, etc.).
    • Update the source code of your zuul project to create the rooms and connections as you designed them.
    • Update the welcome and help messages to match your scenario.
    • The rooms created in your zuul project and the connections from one room to another should match your map.
      • Make sure the connections between rooms are clear in your map. I will assume that connections between rooms are bidirectional unless you indicate otherwise (e.g., with arrowheads).
  2. Test your program.
  3. Document your changes.
    • Adjust the comment block at the top of the file to include a 1-2 sentence description of your specific game scenario.

image text in transcribed

public class Room Code 8.4 Using an accessor method to decrease coupling private String description; private Room northExit; private Room southExit; private Room eastExit; private Room westExit; Existing methods unchanged. public Room getExit(String direction) if(direction.equals("north")) { return northExit; if(direction.equals("east")) { return eastExit; if(direction.equals("south")) { return southExit; } if(direction.equals("west")) { return westExit; return null; Having made this change to the Room class, we need to change the Game class as well. Wherever an exit variable was accessed, we now use the accessor method. For example, instead of writing nextRoom = current Room. east Exit; we now write next Room = current Room.getExit ("east"); This makes coding one section in the Game class much easier as well. In the go Room method, the replacement suggested here will result in the following code segment: Room next Room = null; if(direction.equals("north")) { nextRoom = current Room.getExit("north"): if(direction.equals("east")) { nextRoom = current Room.getExit("east"); if(direction.equals("south")) { nextRoom = currentRoom.getExit("south"); 296 Chapter 8 Designing Classes if(direction.equals("west")) { nextRoom = currentRoom.getExit("west"); Instead, this whole code segment can now be replaced with: Room next Room = currentRoom.getExit(direction); public class Room Code 8.4 Using an accessor method to decrease coupling private String description; private Room northExit; private Room southExit; private Room eastExit; private Room westExit; Existing methods unchanged. public Room getExit(String direction) if(direction.equals("north")) { return northExit; if(direction.equals("east")) { return eastExit; if(direction.equals("south")) { return southExit; } if(direction.equals("west")) { return westExit; return null; Having made this change to the Room class, we need to change the Game class as well. Wherever an exit variable was accessed, we now use the accessor method. For example, instead of writing nextRoom = current Room. east Exit; we now write next Room = current Room.getExit ("east"); This makes coding one section in the Game class much easier as well. In the go Room method, the replacement suggested here will result in the following code segment: Room next Room = null; if(direction.equals("north")) { nextRoom = current Room.getExit("north"): if(direction.equals("east")) { nextRoom = current Room.getExit("east"); if(direction.equals("south")) { nextRoom = currentRoom.getExit("south"); 296 Chapter 8 Designing Classes if(direction.equals("west")) { nextRoom = currentRoom.getExit("west"); Instead, this whole code segment can now be replaced with: Room next Room = currentRoom.getExit(direction)

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

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions

Question

What is Aufbau's rule explain with example?

Answered: 1 week ago

Question

Write Hund's rule?

Answered: 1 week ago

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago