![]() |
![]() |
|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
class files before lecture and class files after lecture.
Recall Robot API:
Methods: currentForm; willBattle;
add getter getIsEvil (but not getShape).
Fields: (ignore)
Robot Hideouts:
Data:
address
pres
vp
anthem
Tasks:
coolestMember
Let's say that one robot
is cooler than another if ... the name of their xformed shape is shorter.]
LESSON: A method should process one type of data --
process nested data with helper functions.
(As things get more and more complicated, it gets too
hard to keep track of things.)
Hideout methods should only work with Hideout fields/info --
if there is code about Robots, make that a Robot method!
Write boolean isInRevolt() , which determines
whether any crew-*members* of this Hideout would attack any other crew-member.
Hint:
A handy helper method would take any Robot r
and any Robot[] crowd ,
and determine whether r would pick a fight with
any member of crowd .
Once this is written, how can you use it to determine whether
each crewmember might combat any other member of the crew?
A method to modify the array:
/** Swap this Hideout's president and a crewmember.
* @param crewIndex The index of which crewmember to make president.
* It must be an integer in [0,this.crew.length).
*/
void elect( /* Hideout this, */ int crewIndex ) { ... }
|
/** Swap this Hideout's president and the most popular crewmember.
*/
void holdElection() { ... }
|
class files before lecture and class files after lecture.
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
| ©2010, Ian Barland, Radford University Last modified 2010.Nov.30 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |