Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part II: Currently the code that generates and displays the list of exits from a room is contained in the Game class. This is not

Part II: Currently the code that generates and displays the list of exits from a room is contained in the Game class. This is not a particularly good design. Each room in the game is represented by a Room object. The Room object contains fields that store the information about that room's exits. Therefore it should seem like this program would be better if the code to generate a list of the exits for a room would be contained in the Room class. Make this improvement by adding a method named getExitString to the Room class. This method should return a String listing the exits from the room. For example, if the room has exits to the north and west, this method should return a String containing: "north west". Now that each Room is capable of generating a list of its own exits. Refactor the code in the Game class to take advantage of this functionality. I.e. anywhere the Game class generates a list of the exits from the current room, change it to use your getExitString method. Written Exercise 2: After making the above improvements to the code, imagine again that you would like to allow rooms to have a new type of exit (e.g. "up"). Now identify each class and method that you would have to change in order to add the new type of exit. Has the design improved? Why or why not? NOTE: Do not actually make these changes at this stage! Currently, the Game class generates the full description of the current room (including information about exits) and displays it. This is dealing with data of the Room class, so the Room class should be responsible for generating this description. Add a method called getLongDescription to the Room class that returns a String containing the description and exits of a room, and refactor the Game class to use it whenever the Game needs to print information about a Room.

In order to answer this question, you need to refer part 1 from the post whose link is shared here....

https://www.chegg.com/homework-help/questions-and-answers/need-code-java-part-imagine-would-like-allow-rooms-new-type-exit-eg--identify-class-method-q34581415

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions