RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lect13a
Objects containing Objects

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 ) { ... }
A 'Before' picture is drawn for you. Draw the picture after calling elect(2).
  /** Swap this Hideout's president and the most popular crewmember.
   */
  void holdElection() { ... }

Consider: what classes, for contact info for employees? public class Employee { private String name; private double salary; // beware round-off if using double! // street, state, zip for home address // street, state, zip for mailing address // street, state, zip for work address // country code, area code, exchange, extension for work phone // country code, area code, exchange, extension for home phone // country code, area code, exchange, extension for cell phone } class ContactInfo { private String email private Address HomeAddr; private Address WorkAddr; private Address PermAddr; private PhoneNumber workNum; private PhoneNumber homeNum; private PhoneNumber cellNum; public String toString() { ... } public boolean equals( ContactInfo that ) { ... } public boolean livesAtPermanent() { ... } } class Address { private String street; private String apt; private String city; private String state; private String zip; private String country; public String toString() { ... } public boolean equals( Address that ) { ... } public boolean sameZip( Address that ) { ... } } class PhoneNumber { private String countryCode; private String areaCode; private String exchange; private String extension; public String toString() { ... } public boolean equals( PhoneNumber that ) { ... } public boolean sameExchange( PhoneNumber that ) { ... } }

class files before lecture and class files after lecture.

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Nov.26 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme