Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you build the loop for a maze using the hug-the-right-wall method In your second program assignment, your task is to create a Jeroo

How do you build the loop for a maze using the hug-the-right-wall method image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
In your second program assignment, your task is to create a Jeroo smart enough to navigate a simple maze, picking all of the flowers and disabling all of the nets: The starting position for your jeroo will always be the southeast corner of the island at (width - 2. height - 2). The starting position for your jeroo will always be the southeast corner of the island at (width - 2. height - 2). After running the maze, the jeroo should always end at the ending position, which is at location (1, 1). The catch is that Maze Island changes every time. Sometimes it is wider, sometimes narrower--the only constant is that it is rectangular and surrounded by water. Flowers can grow anywhere and everywhere on the island. Also, there may be up to fifteen nets located on the island, although there will never be a net at the starting position Further, you will have to write software tests to demonstrate your jeroo can handle this task. How to Walk a Maze While there are many strategies for navigating through a maze, one easy strategy is to simply hug the righthand wall as you walk through the maze--you'll eventually make it all the way through the maze, back to your starting position (hugging the lefthand wall also works the same way, as long as you always stick to one side). If you traverse the maze completely ending back at the starting location you are then ensured that all the flowers and nets have been cleared. Then your Jeroo simply needs to hop to the northwest corner. You can use this strategy to create a simple maze walker for runner) with just a few lines of code. Other strategies are possible, of course, so use the one you find easiest to understand. Structuring Your Solution Download the scenario for this assignment, which contains the Wateisland class: tocam2.zi. In the programa scenario, you do not need to create any island subclasses. Instead, create your own subclass of Seeds called razeliunner, and structure all of your solution code in it. Give your Mazofunner a wyProgram) method that will completely clear the island of all flowers and nets, and then position the jeroo at the ending position. You will need to right click on your Maze Runner class in the Actor classes pane) and select new Maze Runner) and then place it at the southeast corner in the Maze. Although there is no island subclass for program 2. your Maze Runner Program() method will be automatically executed when you press the > Run button. Your Mezeliunner class must provide a constructor that takes no parameters and that creates the jeroo holding 15 flowers (a parameterless constructor is called a default constructor). You can choose to provide additional constructors if you wish. Constructor methods are not inherited by subclasses. However subclass constructors can invoke super class constructors using the superi) keyword. So your Macellunner default..e. parameterless, constructor can invoke the Jeroo super constructor Jeroof int flowers) Remember guidelines for breaking problems up into methods. Including methods that are too long, or methods with poorly chosen names, will lower your score. You will be graded in part on the design and readability of your solution using the posted grading criteria, so consider these factors when devising and naming your methods. The program Grading Rubrice (same as on Program 1) describes the grading criteria. Checking for Nets When writing solutions to this problem, one common question students ask is: "How can I tell if all the nets/flowers are gone?" There are many ways to address the issues of ensuring the Jeroo has completed the task, but one common strategy is to keep going until all the nets are gone and all the flowers are gone. But the Jeroo can only "see" objects nearby, and has no way of determining whether it has found all the nets (for example). However, the island knows how many objects it contains, so it is possible for the Jeroo to ask the island for this information. For example: // Inside a Jeroo method, you can use this expression this.getworld().getObjects(Net.class), 51200) ... Let's break this down: Expression Meaning this The jeroo executing the code this.getWorld Returns the "world" object the Jeroo is in--that is the "istand the Jeroo is on this.getWorld() getObjects...) Gets the "world" object the Jeroo is in, and asks it for a list of all the objects of a specific kind this.getWorld().getObjects(Net.class) Here. "Net.class" is how we specify the kind of object we are looking for--we're actually passing the class called "Net" as an argument to the method. The island will return a list of all the Net objects on the island. this getWorld().getObjects(Net.class.size) Ask the island for a list of all Net objects, and then call the size() method on that list, in order to get a count of how many there are You can use expressions like these in boolean conditions (to compare against integer values, for example), to initialize local variables, or even as parameters to other method calls. Study the way this expression chains together multiple method calls--each one returns a new object, which then becomes the receiver for the next method being invoked. It is really just shorthand for: World myIsland - this.gethorld(); Listchiet alltiets nyistand.getObjects(hiet.class); Int houtany - allets.size(); 1/ A list of Net objects Testing Your Solution You are expected to write software tests to confirm your solution works the way you intend for this assignment. Write a test class for your jeroo called Muzeumertest. Ensure that your test class checks all of the methods you have written We strongly recommend that you write your tests as you write each method in your solution, since it will help you find problems faster. Saving testing until the end usually results in extra time spent trying to find bugs long after they were written. Keep Your Solution Simple When approaching a problem like this, many students start out writing a basic piece of code they hope will run, and then try to "improve" it piece by piece. adding if statements and actions here and there in order to handle the situations they notice as they run their solution on a few islands. However, be aware that this approach may lead to a poor solution. Often, such students end up with code that involves a large number of nested if statements with complicated conditions intended to handle specific situations that the student saw, or with multiple loops that are intended for specialized behaviors on maps with certain kinds of pathways. Please do not do this. You'll end up with a complicated and probably buggy) mess. In truth, the minimal solution to this assignment is not large. You do not need more than one if statement with a simple condition to handle flowers, or more than one if statement with a simple condition to handle nets. Navigation around the island can be done with as few as two it statements, and no boolean AND or OR operators are needed. You can also create a solution with one for perhaps two) loops. If, instead, you find yourself with very long methods (more than a handful of lines) involving many if statements (or many else-If branches that use complicated conditions with lots of &&'s and Ils scattered around, then that is a warning sign that your solution is difficult to read, difficult to understand, and poorly planned. For writing your tests, you can pick your own number for numbers) and use it to create exactly the same island layout over and over. This will give you a fixed, predictable situation for testing testing individual pieces of your solution. Expectations for your test class are as follows: 1. For each method in your solution that has no control statements (ie.. no if statements, loops, etc.), you should write one test method to confirm that method works as intended. 2. For each loop contained in any method, you should write two separate test methods: one that exercises the method in a situation where the loop is completely skipped, and one that exercises it in a situation where the loop repeats more than once. 3. For each it statement in any method, you should write a separate test method for each branch (for each if, each else-it, and each else) that exercises the method in a situation where that branch is executed. 4. If your logic or your control statements are particularly complicated, you might need to ask for help about what else you should test. You can easily write software tests that follow this pattern Create an island using the code number you have selected so it is the same every time) Add your jero at a specific location of your choosing on that Island in order to set up the situation needed for the method/condition you are trying to . . test . Call the method you intend to test Confirm that the desired behavior was achieved In your second program assignment, your task is to create a Jeroo smart enough to navigate a simple maze, picking all of the flowers and disabling all of the nets: The starting position for your jeroo will always be the southeast corner of the island at (width - 2. height - 2). The starting position for your jeroo will always be the southeast corner of the island at (width - 2. height - 2). After running the maze, the jeroo should always end at the ending position, which is at location (1, 1). The catch is that Maze Island changes every time. Sometimes it is wider, sometimes narrower--the only constant is that it is rectangular and surrounded by water. Flowers can grow anywhere and everywhere on the island. Also, there may be up to fifteen nets located on the island, although there will never be a net at the starting position Further, you will have to write software tests to demonstrate your jeroo can handle this task. How to Walk a Maze While there are many strategies for navigating through a maze, one easy strategy is to simply hug the righthand wall as you walk through the maze--you'll eventually make it all the way through the maze, back to your starting position (hugging the lefthand wall also works the same way, as long as you always stick to one side). If you traverse the maze completely ending back at the starting location you are then ensured that all the flowers and nets have been cleared. Then your Jeroo simply needs to hop to the northwest corner. You can use this strategy to create a simple maze walker for runner) with just a few lines of code. Other strategies are possible, of course, so use the one you find easiest to understand. Structuring Your Solution Download the scenario for this assignment, which contains the Wateisland class: tocam2.zi. In the programa scenario, you do not need to create any island subclasses. Instead, create your own subclass of Seeds called razeliunner, and structure all of your solution code in it. Give your Mazofunner a wyProgram) method that will completely clear the island of all flowers and nets, and then position the jeroo at the ending position. You will need to right click on your Maze Runner class in the Actor classes pane) and select new Maze Runner) and then place it at the southeast corner in the Maze. Although there is no island subclass for program 2. your Maze Runner Program() method will be automatically executed when you press the > Run button. Your Mezeliunner class must provide a constructor that takes no parameters and that creates the jeroo holding 15 flowers (a parameterless constructor is called a default constructor). You can choose to provide additional constructors if you wish. Constructor methods are not inherited by subclasses. However subclass constructors can invoke super class constructors using the superi) keyword. So your Macellunner default..e. parameterless, constructor can invoke the Jeroo super constructor Jeroof int flowers) Remember guidelines for breaking problems up into methods. Including methods that are too long, or methods with poorly chosen names, will lower your score. You will be graded in part on the design and readability of your solution using the posted grading criteria, so consider these factors when devising and naming your methods. The program Grading Rubrice (same as on Program 1) describes the grading criteria. Checking for Nets When writing solutions to this problem, one common question students ask is: "How can I tell if all the nets/flowers are gone?" There are many ways to address the issues of ensuring the Jeroo has completed the task, but one common strategy is to keep going until all the nets are gone and all the flowers are gone. But the Jeroo can only "see" objects nearby, and has no way of determining whether it has found all the nets (for example). However, the island knows how many objects it contains, so it is possible for the Jeroo to ask the island for this information. For example: // Inside a Jeroo method, you can use this expression this.getworld().getObjects(Net.class), 51200) ... Let's break this down: Expression Meaning this The jeroo executing the code this.getWorld Returns the "world" object the Jeroo is in--that is the "istand the Jeroo is on this.getWorld() getObjects...) Gets the "world" object the Jeroo is in, and asks it for a list of all the objects of a specific kind this.getWorld().getObjects(Net.class) Here. "Net.class" is how we specify the kind of object we are looking for--we're actually passing the class called "Net" as an argument to the method. The island will return a list of all the Net objects on the island. this getWorld().getObjects(Net.class.size) Ask the island for a list of all Net objects, and then call the size() method on that list, in order to get a count of how many there are You can use expressions like these in boolean conditions (to compare against integer values, for example), to initialize local variables, or even as parameters to other method calls. Study the way this expression chains together multiple method calls--each one returns a new object, which then becomes the receiver for the next method being invoked. It is really just shorthand for: World myIsland - this.gethorld(); Listchiet alltiets nyistand.getObjects(hiet.class); Int houtany - allets.size(); 1/ A list of Net objects Testing Your Solution You are expected to write software tests to confirm your solution works the way you intend for this assignment. Write a test class for your jeroo called Muzeumertest. Ensure that your test class checks all of the methods you have written We strongly recommend that you write your tests as you write each method in your solution, since it will help you find problems faster. Saving testing until the end usually results in extra time spent trying to find bugs long after they were written. Keep Your Solution Simple When approaching a problem like this, many students start out writing a basic piece of code they hope will run, and then try to "improve" it piece by piece. adding if statements and actions here and there in order to handle the situations they notice as they run their solution on a few islands. However, be aware that this approach may lead to a poor solution. Often, such students end up with code that involves a large number of nested if statements with complicated conditions intended to handle specific situations that the student saw, or with multiple loops that are intended for specialized behaviors on maps with certain kinds of pathways. Please do not do this. You'll end up with a complicated and probably buggy) mess. In truth, the minimal solution to this assignment is not large. You do not need more than one if statement with a simple condition to handle flowers, or more than one if statement with a simple condition to handle nets. Navigation around the island can be done with as few as two it statements, and no boolean AND or OR operators are needed. You can also create a solution with one for perhaps two) loops. If, instead, you find yourself with very long methods (more than a handful of lines) involving many if statements (or many else-If branches that use complicated conditions with lots of &&'s and Ils scattered around, then that is a warning sign that your solution is difficult to read, difficult to understand, and poorly planned. For writing your tests, you can pick your own number for numbers) and use it to create exactly the same island layout over and over. This will give you a fixed, predictable situation for testing testing individual pieces of your solution. Expectations for your test class are as follows: 1. For each method in your solution that has no control statements (ie.. no if statements, loops, etc.), you should write one test method to confirm that method works as intended. 2. For each loop contained in any method, you should write two separate test methods: one that exercises the method in a situation where the loop is completely skipped, and one that exercises it in a situation where the loop repeats more than once. 3. For each it statement in any method, you should write a separate test method for each branch (for each if, each else-it, and each else) that exercises the method in a situation where that branch is executed. 4. If your logic or your control statements are particularly complicated, you might need to ask for help about what else you should test. You can easily write software tests that follow this pattern Create an island using the code number you have selected so it is the same every time) Add your jero at a specific location of your choosing on that Island in order to set up the situation needed for the method/condition you are trying to . . test . Call the method you intend to test Confirm that the desired behavior was achieved

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

More Books

Students also viewed these Databases questions

Question

3. Describe the communicative power of group affiliations

Answered: 1 week ago