Question: Now that your first test is written, switch back to your jeroo subclass and write a stub for the method you decided to test /

Now that your first test is written, switch back to your jeroo subclass and write a stub for the method you decided to test/work on. Then compile and run your test (it should fail).
Now begin implementing your method. Compile and re-run your test as needed to confirm whether or not your method works. Continue until you have it implemented to behave the way you intend.
Repeat the testing and implementation of your remaining methods
Repeat Steps 3(e)-(g) for each remaining method in the list you brainstormed. Your test cases should be much less repetitious, since you now have a setUp() method that captures the starting conditions. Remember to re-compile and re-run your tests to double-check your work as you go.
If you wish for a particular test to start out with the jeroo at a different starting position, leave your setUp() method alone. In your test case, you can simply "move" the jeroo to a new position before carrying out the remainder of your test. If you want the jeroo to be at (someX, someY), then you can do this at the start of your test case:
// jeroo is the field in your test class referring to your jeroo: jeroo.setLocation(someX, someY);
Once you believe you have implemented and tested enough methods to complete the task, you are ready to move on to the next step.
Part 2: Delegating to a Buddy
Now it is time to create a second jeroo that your copyingjeroo can control.
Procedure
Create a field
Add a field to your CopyingJeroo class that refers to a second Jeroo. Let's call this field copier, since it will be responsible for creating the copy of the flower arrangement.
Modify the constructor for CopyingJeroo so that it takes another Jeroo as a parameter. Inside the constructor, use the parameter to initialize your field.
Now we need to modify your test class to include this second jeroo as well, (right now, your test class will no longer compile correctly!).
Add another field to your test class that refers to a Jeroo. Let's call this field "copier" as well, since it will refer to the "mimic" that your jeroo will command to make a copy of the flower arrangement.
Modify setUp() to create a new Jeroo object that starts out with 1,000 flowers in its pouch. Be sure to create it before creating your copyingjeroo within setUp(). Assign this new jeroo to your "copier" field and add it to the island at location (10,1), the upper-left corner of the righthand island. Finally, modify the constructor call for your CopyingJeroo to include this second jeroo as the argument to the constructor.
Recompile and re-run your tests. The jeroo on the left island should behave as before, while the jeroo on the right island just stands there and does nothing.
Write down your expectations
Eventually, you'll want the second jeroo to trace out exactly the same steps as your CopyingJeroo. Take a look at the tests you have written. For each assertion regarding the first jeroo, what assertion(s) can you add about what you expect of the second jeroo at that same point in time? Add those assertions (they will fail now, but should pass once you implement more of the solution).
Override methods
Override the hop() method in your CopyingJeroo so that it hops itself, and also has the copier jeroo hop as well.
Override the turn() method in your CopyingJeroo so that it turns itself, and also has the copier jeroo turn in the same direction.
Re-run your tests to see if the copier jeroo moves as expected. Fix problems, recompile, and re-run until your copier jeroo is doing what you want.
Decide where in the action of your CopyingJeroo you want to check for a flower in some cell, and command the copier jeroo to plant a corresponding flower. After you have made this decision, write a test case for the method that performs this check (hint: you can reposition the jerooat the start of your test if needed).
If you haven't already, make the changes to your CopyingJeroo to have it check for a flower at each step, and command the copier to plant corresponding flowers. Run your tests and fix any problems.
Edit the walkIsland() method
Edit your CopyingJeroo subclass and complete the definition for the walkIsland() method that causes the jeroo to traverse the whole island. The body of walkIsland() probably just uses one or more of the methods you wrote earlier.
Write a test case in your test class for walkIsland() that confirms that the entire flower pattern is copied.
For fun: a random flower arrangement

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!