home—info—lects—labs—exams—hws
D2L—tutor/PIs—zoom (snow day)
Object120 + its docs—java.lang docs—java.util docs
mutation practice
robots
For this lab, we'll continue our class Robot from a previous lab's class Robot task.
Alternately, you base your code off this class.
-
Make sure your code compiles, before we start modifying it.
-
Change the constructor to not use super (which works only because of Object120);
instead, assign to each field as a normal, routine constructor does.
(You probably do still want to extends Object120, though,
so that you can use a full assertEquals.)
-
Write the getter-method getPower field.
Add unit-tests for it first.
(Compare with our lecture notes on Mutation!.)
-
Write a setter-method for the power field.
Add unit-tests for it first.
Hint:
First assert that the field is its initial value, then call your void method,
and then do an assertEquals with the resulting robot, to ensure it's changed.
You might want to See the tests provided in hw05 file
TestArrayPractice.java,
for the method changeMaxesToMin.
-
Write Robot#powerUp(Robot,double): it increases the robot's power by the indicated amount.
(You should call the getter and setter for that field!)
-
Write Robot#defeat(Robot,Robot): When one robot (the first) defeats another (the second),
the defeated robot's weight is cut in half;
the victor's weight increases by half the defeated robot's weight;
the victor's own transformed shape becomes the defeated robot's shape;
and the defeated robot's shape becomes just "Robot".
(You should use the getter/setter for the power,
but (since we haven't written it), you can access the shape field directly.
This will let us compare these two approaches, later.)
home—info—lects—labs—exams—hws
D2L—tutor/PIs—zoom (snow day)
Object120 + its docs—java.lang docs—java.util docs
 This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland radford.edu |
 |