Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If you need more information, please let me know what kind of information you need in order for me to know what you are looking

If you need more information, please let me know what kind of information you need in order for me to know what you are looking for. This was all that was given to me. Thank you.

I am tasked with editing the "RoomNavigator.java" code by filling in Steps 1 (create and populate Room map with the rooms in the list), 2 (create Breadth-First Search queue and start with initial room), and 3 (in a loop, repeatedly process next Room in the queue). Essentially, there are rooms that are listed in the "layout.txt" section. For example, if we start on Ground Floor in the Entrance Hall and want to end in the Dining Hall, the only room available would be the Foyer at the Entrance Hall. Then the Foyer would have 4 rooms and etc. The code would need to involve the Breadth-First Search in order to look through the list of rooms that are available to walk to. Most of the code is written out for me, and I worked through some of it, but I am unsure if I am even doing it right or not.

The screenshots underneath are the steps in order to achieve this. I was told to give more information and I included what I could. And now I am told that it's too much, so now I have to trim.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Starter Code

Room.java

image text in transcribed

RoomNavigator.java (code to be edited)

image text in transcribedimage text in transcribed

layout.txt:

Entrance Hall; Foyer Foyer; Entrance Hall, Library, Dining Hall, Conservatory Conservatory; Foyer, Graveyard, Gardens Graveyard; Conservatory Gardens; Conservatory Library; Foyer, Storeroom Storeroom; Library, Larder Larder; Storeroom, Kitchen Kitchen; Larder, Charred Room, Dining Hall Charred Room; Kitchen Dining Hall; Kitchen, Patio, Foyer, Ballroom Ballroom; Dining Hall Patio; Dining Hall

Upper Landing; Dusty Hallway Dusty Hallway; Upper Landing, Game Room, Collapsed Room, Bedroom Game Room; Dusty Hallway Collapsed Room; Dusty Hallway Bedroom; Dusty Hallway, Junk Room, Balcony, Creaky Hallway Balcony; Bedroom Junk Room; Bedroom, Abandoned Room Creaky Hallway; Bedroom, Abandoned Room, Chasm Chasm; Creaky Hallway, Tower Tower; Chasm Abandoned Room; Creaky Hallway, Junk Room, Attic Attic; Abandoned Room

Basement Landing; Catacombs Catacombs; Basement Landing, Chapel, Crypt, Statuary Corridor Chapel; Catacombs Crypt; Catacombs Statuary Corridor; Catacombs, Underground Lake, Furnace Room, Gallery Underground Lake; Statuary Corridor Furnace Room; Statuary Corridor Gallery; Statuary Corridor, Research Laboratory, Vault Research Laboratory; Gallery Vault; Gallery, Wine Cellar Wine Cellar; Vault

Room Layout:

image text in transcribed

image text in transcribed

image text in transcribed

To accomplish this, you'll make use of several different collections and a simple breadth-first search algorithm. See Breadth-First Search below for the detailed steps! When your implementation is complete, you should be able to call doesPathExist with different starting rooms and ending rooms and find varying answers (see the main method, which has a few sample calls). Every room is reachable from every other room on the same floor, but you'll notice there's no way to move between floors. If you ask whether a path exists between a ground floor room and a basement room, for example, the answer should be false. Assignment Setup Download the file named Starter Code from iLearn. It is a .zip file which can be extracted to whatever location you want on your computer. Set up an IntelliJ project in the unzipped directory. For step-by-step instructions on setting up an IntelliJ project, see the IntelliJ Setup Guide handout on iLearn (at the top of the iLearn course page). Detailed Requirements In this assignment, all of your changes should be limited to the doesPathExist method, as that is what I'll be grading. Feel free to add your own code to main for testing, however. Breadth-First Search At a Glance The algorithm we'll use to determine whether we can find a path from a start location to a destination is called breadth-first search. 1. Begin at the start location (the starting room). 2. Look at every location that is one step away. Are any of these the destination? 3. Look at every location that is one step away from the rooms in #2. Are any of these the destination? 4. Look at every location that is one step away from the rooms in #3. Are any of these the destination? 5. etc.... At any point in this process, if a location you're looking at is the destination, then you've found a path and you're finished! But if you continue searching and eventually exhaust all of your search options without finding the destination, you can safely say that no such path exists. In the Room Navigator program, the locations that are one step away from a room are all it's connected neighbors. We will use the getConnectedRooms () method in implementing breadth-first search! But first... Setting Up Your Collections If you try to jump straight into implementing the breadth-first search algorithm described above, you're going to run into a major problem fairly quickly. Suppose you have a Room object and want to know what rooms you can reach. Room room = // ... ArrayList connectedRooms = room.getConnectedRooms(); It's simple enough to get a list of the immediately connected rooms. But how do we find all the rooms that are connected to those rooms? for (int i = 0; i connectedRooms; - public Room(String name) { this.name = name; this.connectedRooms = new ArrayList(); } public String getName() { return name; } public ArrayList getConnectedRooms() { return new ArrayList(connectedRooms); } public void addConnectedRoom (String roomName) { connectedRooms.add(roomName); } } 1 package edu.csc220.navigator; 3 4 import java.io. BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.*; 5 6 7. public class RoomNavigator { 9 10 11 12 13 /** * Returns true if and only if a path exists between the start room and the end room, based on the description of * rooms provided by the allrooms list. The start and end rooms are specified by their names. */ public boolean doesPathExist(ArrayList allrooms, String startRoom, String endRoom) { // TODO: Implement. Step 1: create and populate your Room map with everything from the rooms list. 14 15 16 17 18 19 // TODO: Implement. Step 2: create your breadth-first search queue and start it off with the initial room. // TODO: Implement. Step 3: in a loop, repeatedly process the next Room in the queue. 20 21 22 return false; } 23 24 25 /** Program execution begins here. */ public static void main(String[] args) { ArrayList allrooms = readRooms(); RoomNavigator navigator = new RoomNavigator(); 26 27 28 // Paths between rooms that are on the same floor (expecting 'true'): LookForPath(navigator, allrooms, startRoom: "Larder", endRoom: "Gardens"); LookForPath(navigator, allrooms, startRoom: "Upper Landing", endRoom: "Attic"); LookForPath(navigator, allrooms, startRoom: "Chapel", endRoom: "Wine Cellar"); 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 @ 45 // Paths between rooms that are on different floors (expecting 'false'): LookForPath(navigator, allrooms, startRoom: "Patio", endRoom: "Game Room"); LookForPath(navigator, allrooms, startRoom: "Tower", endRoom: "Crypt"); LookForPath(navigator, allrooms, startRoom: "Underground Lake", endRoom: "Library"); } * Reads the "layout.txt" file and creates a list of Room objects with their connections set up accordingly. You * should not modify this method in way. private static ArrayList readRooms() { ArrayList rooms = new ArrayList(); private static ArrayList readRooms() { ArrayList rooms = new ArrayList(); try { BufferedReader bufferedReader = new BufferedReader(new FileReader( fileName: "layout.txt")); String line; while ((line = bufferedReader.readLine()) != null) { if (line.strip().isEmpty()) { continue; } int splitIndex = line.indexOf(';'); if (splitIndex allrooms, String startRoom, String endRoom) { System.out.printf( "Path from '%s' to '%s': %s%n", startRoom, endRoom, navigator.doesPathExist(allrooms, startRoom, endRoom)); } } Ground Floor Charred Room Patio Larder Kitchen Dining Hall Ballroom Storeroom Library Foyer Conservatory Graveyard Entrance Hall Gardens Upper Floor Larder Abandoned Room Creaky Hallway Chasm Tower Junk Room Bedroom Balcony Collapsed Room Dusty Hallway Game Room Upper Landing Basement Wine Cellar Vault Gallery Research Laboratory Underground Lake Statuary Corridor Furnace Room Crypt Catacombs Chapel Basement Landing To accomplish this, you'll make use of several different collections and a simple breadth-first search algorithm. See Breadth-First Search below for the detailed steps! When your implementation is complete, you should be able to call doesPathExist with different starting rooms and ending rooms and find varying answers (see the main method, which has a few sample calls). Every room is reachable from every other room on the same floor, but you'll notice there's no way to move between floors. If you ask whether a path exists between a ground floor room and a basement room, for example, the answer should be false. Assignment Setup Download the file named Starter Code from iLearn. It is a .zip file which can be extracted to whatever location you want on your computer. Set up an IntelliJ project in the unzipped directory. For step-by-step instructions on setting up an IntelliJ project, see the IntelliJ Setup Guide handout on iLearn (at the top of the iLearn course page). Detailed Requirements In this assignment, all of your changes should be limited to the doesPathExist method, as that is what I'll be grading. Feel free to add your own code to main for testing, however. Breadth-First Search At a Glance The algorithm we'll use to determine whether we can find a path from a start location to a destination is called breadth-first search. 1. Begin at the start location (the starting room). 2. Look at every location that is one step away. Are any of these the destination? 3. Look at every location that is one step away from the rooms in #2. Are any of these the destination? 4. Look at every location that is one step away from the rooms in #3. Are any of these the destination? 5. etc.... At any point in this process, if a location you're looking at is the destination, then you've found a path and you're finished! But if you continue searching and eventually exhaust all of your search options without finding the destination, you can safely say that no such path exists. In the Room Navigator program, the locations that are one step away from a room are all it's connected neighbors. We will use the getConnectedRooms () method in implementing breadth-first search! But first... Setting Up Your Collections If you try to jump straight into implementing the breadth-first search algorithm described above, you're going to run into a major problem fairly quickly. Suppose you have a Room object and want to know what rooms you can reach. Room room = // ... ArrayList connectedRooms = room.getConnectedRooms(); It's simple enough to get a list of the immediately connected rooms. But how do we find all the rooms that are connected to those rooms? for (int i = 0; i connectedRooms; - public Room(String name) { this.name = name; this.connectedRooms = new ArrayList(); } public String getName() { return name; } public ArrayList getConnectedRooms() { return new ArrayList(connectedRooms); } public void addConnectedRoom (String roomName) { connectedRooms.add(roomName); } } 1 package edu.csc220.navigator; 3 4 import java.io. BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.*; 5 6 7. public class RoomNavigator { 9 10 11 12 13 /** * Returns true if and only if a path exists between the start room and the end room, based on the description of * rooms provided by the allrooms list. The start and end rooms are specified by their names. */ public boolean doesPathExist(ArrayList allrooms, String startRoom, String endRoom) { // TODO: Implement. Step 1: create and populate your Room map with everything from the rooms list. 14 15 16 17 18 19 // TODO: Implement. Step 2: create your breadth-first search queue and start it off with the initial room. // TODO: Implement. Step 3: in a loop, repeatedly process the next Room in the queue. 20 21 22 return false; } 23 24 25 /** Program execution begins here. */ public static void main(String[] args) { ArrayList allrooms = readRooms(); RoomNavigator navigator = new RoomNavigator(); 26 27 28 // Paths between rooms that are on the same floor (expecting 'true'): LookForPath(navigator, allrooms, startRoom: "Larder", endRoom: "Gardens"); LookForPath(navigator, allrooms, startRoom: "Upper Landing", endRoom: "Attic"); LookForPath(navigator, allrooms, startRoom: "Chapel", endRoom: "Wine Cellar"); 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 @ 45 // Paths between rooms that are on different floors (expecting 'false'): LookForPath(navigator, allrooms, startRoom: "Patio", endRoom: "Game Room"); LookForPath(navigator, allrooms, startRoom: "Tower", endRoom: "Crypt"); LookForPath(navigator, allrooms, startRoom: "Underground Lake", endRoom: "Library"); } * Reads the "layout.txt" file and creates a list of Room objects with their connections set up accordingly. You * should not modify this method in way. private static ArrayList readRooms() { ArrayList rooms = new ArrayList(); private static ArrayList readRooms() { ArrayList rooms = new ArrayList(); try { BufferedReader bufferedReader = new BufferedReader(new FileReader( fileName: "layout.txt")); String line; while ((line = bufferedReader.readLine()) != null) { if (line.strip().isEmpty()) { continue; } int splitIndex = line.indexOf(';'); if (splitIndex allrooms, String startRoom, String endRoom) { System.out.printf( "Path from '%s' to '%s': %s%n", startRoom, endRoom, navigator.doesPathExist(allrooms, startRoom, endRoom)); } } Ground Floor Charred Room Patio Larder Kitchen Dining Hall Ballroom Storeroom Library Foyer Conservatory Graveyard Entrance Hall Gardens Upper Floor Larder Abandoned Room Creaky Hallway Chasm Tower Junk Room Bedroom Balcony Collapsed Room Dusty Hallway Game Room Upper Landing Basement Wine Cellar Vault Gallery Research Laboratory Underground Lake Statuary Corridor Furnace Room Crypt Catacombs Chapel Basement Landing

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

Students also viewed these Databases questions

Question

Write the difference between sexual and asexual reproduction.

Answered: 1 week ago

Question

What your favourite topic in mathematics?

Answered: 1 week ago