Lab 03
Due Friday by 4pm Points 100 Available Jul 11 at 4pm Jul 13 at 4pm 2 days
Repea�ng Ac�ons
In your third laboratory assignment, you will be writing a custom Jeroo subclass, but this time one that can
deal with unknown distances and quantities. Your Jeroo will start off on an island containing a line of flowers
and a long, straight line of nets, but you won't know how many flowers or where the line of nets is located
(Keep in mind that the line of flowers will always start at (3, 1) and the line of nets will always start at the top
of your island but the amount of flowers and nets will vary as well as the xcoordinate of your line of nets).
You will need to navigate your Jeroo to collect all of the flowers, then find the line of nets, and finally use the
flowers to disable as many of the nets as possible (there might be more nets, or more flowers, but you won't
know).
Star�ng Materials
Download the zip file for this lab and unzip it into your CS1114 folder: lab03.zip. This zip file contains a
folder called lab03 that is a Greenfoot4Sofia scenario. This is the scenario we'll be working with today.
Open the lab03 scenario in Greenfoot4Sofia. In includes an island subclass called NetIsland that looks
something like this:
2018/7/13 Lab 03
https://canvas.vt.edu/courses/70501/assignments/445354 2/6
Your goal will be writing a Jeroo subclass that can pick all the flowers and disable as many nets as possible.
Part 1: Crea�ng Classes
Procedure
1. Reset a few times
a. When you open the project, you should see the initial layout for the NetIsland class. Note that the
exact number of flowers, the xcoordinate of the line of nets, and the number of nets, are all different
every time.
b. Press the Reset button in Greenfoot4Sofia to replace the current island with a brand new instance of
the class. Do this several times to see some of the variation possible in the layout of the island.
2. Create a Jeroo subclass
a. Rightclick on the Jeroo class and create a new subclass called NetRemover (you must use this
name).
b. Edit the source code for your jeroo subclass. Complete all of the comments.
c. Change the constructor in your NetRemover class so that it takes two parameters representing the x
and y coordinates (refer back to Lab 02 if you need a reminder about how to do this).
2018/7/13 Lab 03
https://canvas.vt.edu/courses/70501/assignments/445354 3/6
3. Create an Island subclass
a. Rightclick on NetIsland and create a new subclass called Lab03Solution (you must use this name;
be careful of capitalization).
b. Edit the source code for your island subclass. Complete all of the comments.
c. Locate the body of the constructor for your new island subclass. Add a line to create a new
NetRemover at location (3, 1), and a second line to add it to the island. Do not add a myProgram()
method to the island subclass, (i.e. Lab03Solution).
d. Compile your code and run it to check that the world appears correctly, with one Jeroo at the starting
position. Note: after compiling your island subclass, you must rightclick on it and create an
instance before it will show in the main area of the screen. If you don't do that, you'll still be
seeing the NetIsland class rather than your subclass, and none of your changes will appear to have
any effect.
Part 2: Crea�ng Methods for Your Solu�on
Procedure
1. Add methods to your jeroo subclass
a. Create a stub for myProgram() in your NetRemover class (recall that a stub is an empty method
body that serves as a placeholder for behavior. you will add later).
b. Devise a plan for how you will accomplish the task in this labcollecting the flowers and disabling
the nets. Write your plan in the form. of comments in your Jeroo's myProgram() method.
c. Think carefully about which of your steps will make meaningful methods. Pick good names for
your methods. As an example, remember that we wrote this method in class (you can use it as a
general pattern for creating your own methods for this lab):
public void pickFlowers()
{
while (this.seesFlower(AHEAD))
{
this.hop();
this.pick();
}
}
d. Work incrementally to write and check your solution. Feel free to write stubs for your own
methods.
e. As you add pieces of your solution, don't forget to compile your code and run it to confirm that it
works as you expect. Fix any problems you see.
f. Don't forget to use while loops when you need to repeat an action, and if-then-else structures
when you wish to choose between alternate actions. You can review information on if-then-then
and if-then in Chapter 6 (http://courses.cs.vt.edu/~cs1114/booklet/chapter6.html) , and review
2018/7/13 Lab 03
https://canvas.vt.edu/courses/70501/assignments/445354 4/6
information on while loops in Chapter 7 (http://courses.cs.vt.edu/~cs1114/booklet/chapter7.html) .
The basic form. of these structures is shown below for reference:
// Use a while loop for repetition:
while ()
{
// actions here will be repeated as long as the is true
}
// Use an if-then for optional actions
if ()
{
// actions here will only be executed if the is true,
// or skipped if the is false
}
// Use an if-then-else for choosing between two actions
if ()
{
// actions here will only be executed if the is true
}
else
{
// actions here will only be executed if the is false
}
Part 3: Submi�ng Your Work
Procedure
1. Submit to WebCAT
a. Make sure your lab03 scenario is the only one you have open, and submit it using th Controls
Submit... menu command.
b. Correct any issues and resubmit your work until you are happy with your score.
c. If you are unsure why points are being deducted in your assignment, or if you are unsure how
to address a particular issue, ask a neighbor or a TA.
Part 4: Developing an Error Catalog
In this last part of the lab assignment, you will intentionally introduce errors into the source code you have
been working with. The Java compiler (as well as compilers in general) is not perfect by any meansit
cannot always make intelligent guesses as to what the programmer may have meant when he or she makes
an error, and the messages that the compiler produces do not necessarily always point to the obvious cause