|
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! Writeboolean isInRevolt() , which determines whether any crew-*members* of this Hideout would attack any other crew-member.Hint: A handy helper method would take anyA method to modify the array:Robot r and anyRobot[] crowd , and determine whetherr would pick a fight with any member ofcrowd .
Once this is written, how can you use it to determine whether each crewmember might combat any other member of the crew?
/** 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
©2012, Ian Barland, Radford University Last modified 2012.Nov.26 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |