|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
Self-Test:
class Blarg { private int zzmph; // &vdots; // Other fields/methods omitted // &vdots; } |
Also, we'll see motivation today for the following rule-of-thumb,
about access modifiers (
Fields should be declared ;
almost all methods should be declared .
We will develop a class to represent the
Initial source files:
lect13a-hideout.jar; see
how-to-get-jar-files-into-BlueJ—Downloading .jar files into BlueJ.
We won't turn in today's work,
though it will practice the concepts that will be needed for the last hw.
Lesson: A method should process one type of data -- process nested data with helper functions.The reason for this is that in real programs, the data gets more complicated: It's not at all far-fetched to want to have an array of
Should this method be static, or not?
Well, ideally, it would be a non-static method inside some class "array-of-Robot"
(and we'd walk up to the array-object, and ask it to toString itself).
However, there isn't really such a class in Java (!?),
so we'll fake it: we'll make this a
int a = 93 int b = 17; // Now, we try to swap the contents of these two local variables: a = b; b = a; // What do things look like? |
/** 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 ) { /* stub */ } |
/** Swap this Hideout's president and the most popular crewmember. */ void holdElection() { ... } |
Hint: A handy helper method would take anyRobot 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?
Hideout.java
(and one helper function (
Files/solution as completed in lecture: lect13a-sect04-hideout/.
1
In the past we've just called this “
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.Dec.04 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |