Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
You may work on this assignment alone or in a group.
You must be checked-off at the end of the lab period. Otherwise, you must submit a hardcopy of the worksheet before 5:00PM today.
Getting Ready: Before going any further, you should:
downloads
directory/folder). In most browsers/OSs, the
easiest way to do this is by right-clicking/control-clicking on
each of the links above and then selecting
robotics.jar contains a
Direction.class
and Robot.class
,
both of which are in the robotics
package.
ColorFinder.arraylists
from
your solution to the lab on "Experimenting with Collections I"
to your directory for this lab.
ColorFinder.arraylists
to ColorFinder.java
.
colors
so
that it is a List
of Color
objects.
names
so
that it is a List
of String
objects.
colors
and names
objects.
getColor()
method so that it no longer
casts the objects returned by the calls to
get()
.
ColorFinder.java
to ColorFinder.arraylists
.
Map
objects.
ColorFinder.hashmap
from
your solution to the lab on "Experimenting with Collections I"
to your directory for this lab.
ColorFinder.hashmap
to ColorFinder.java
.
colors
so
that it is a Map
that uses String
objects
for keys and Color
objects for values.
colors
object as (an appropriately
typed) HashMap
ColorFinder.java
to ColorFinder.hashmap
.
Bender
and Driver1
classes.
Robot
class includes the following methods:
protected boolean canMove(Direction d)
protected void move(Direction d)
protected boolean haveBeen(Direction d)
Complete the execute()
method in the Bender
class using these methods based on the comments describing
this method. (Note: You need not use
the haveBeen()
method.) Do not use an Iterator
.
Driver1
.
execute()
method so that it uses an
Iterator
.
execute()
method now?
Driver2
class.
Bender
class and complete it. (For this question you should
assume that there are four directions: Direction.FORWARD
,
Direction.RIGHT
, Direction.BACKWARD
, and
Direction.LEFT
.)
* Read instructions from a file * * @param name The name of the file * @return An ArrayList of Direction objects */ public List<Direction> read(String name) { }
Driver2
.
Direction
class includes
Direction.CONTINUE
. Add a line to the read()
method that accounts for this Direction
.
execute()
method so that it handles
Direction.CONTINUE
. Specifically, when a
Direction.CONTINUE
is encountered the execute()
method must get the next element in the method
collection and then
repeatedly move the Robot
in that direction until
it can no longer do so.
Driver3
.
Bender
class:
private Map<String, List<Direction>> library;
library
attribute in the constructor
of the Bender
class.
Bender
class and complete it:
/** * Add a method to the existing library * * @param method The method to add */ public void add(String name, List<Direction> method) { }
Bender
class and complete it:
/** * Execute a named set of instructions from the library. * Specifically, retrieve a named set of instructions from * the library and then call the other version of * execute(). * * @param name The name of the method */ public void execute(String name) { }
Driver3
.
Copyright 2024