Java newbie here............need help !

Discussion in 'OT Technology' started by Nuttycrack, Oct 11, 2004.

  1. Nuttycrack

    Nuttycrack New Member

    Joined:
    Apr 29, 2004
    Messages:
    2,529
    Likes Received:
    0
    Location:
    Toronto
    Hi

    i am doing an assignment and i have a lot of trouble on writing methods ........

    here is the part that i am having trouble on

    isOlder(FamilyMember)

    Return true if this family member is older than the given family member, false otherwise. In this case, 'older' simply means that one person's age is strictly greater than the other, and is not related to one's birth day or birth month.

    areSameAge(FamilyMember,
    FamilyMember)

    Static method. Return true if the two people represented by the given FamilyMember objects have the same age, false otherwise. Again, only use the age of the family members in your comparison, not the birthdays.

    areRelated(FamilyMember,
    FamilyMember)

    Static method. Return true if the two people represented by the given FamilyMember objects have the same last name, false otherwise. For this method, capitalization is not important (i.e. "Grease" and "grease" are the same last name).

    isBrother(FamilyMember)

    Return true if this family member is the brother of the given family member, false otherwise. In this family, a guy is still called your brother even if you only have one parent in common. (i.e. no stepbrothers)

    isSister(FamilyMember)

    Return true if this family member is the sister of the given family member, false otherwise. As stated above, a girl is still called your sister even if you only have one parent in common. (i.e. no stepsisters)

    areSiblings(FamilyMember,
    FamilyMember)

    Static method. Return true if the two people represented by the given FamilyMember objects are siblings, false otherwise.

    isMother(FamilyMember)

    Return true if this family member is the mother of the given family member, false otherwise.

    isFather(FamilyMember)

    Return true if this family member is the father of the given family member, false otherwise.

    isParent(FamilyMember)

    Return true if this family member is the parent of the given family member, false otherwise.

    areTwins(FamilyMember,
    FamilyMember)

    Return true if the two FamilyMembers have the same age, birthday, and birth month, false otherwise.

    isEvilTwin(FamilyMember)

    Return true if this family member is the evil twin of the given family member. In this case, being 'evil' means having a criminal record. (Which we realize is a gross generalization.)



    can somebody teach me how to do it ?? just a couple of them, because i know that a lot of them are similar

    but Do not use if statements when completing this assignment. Using the && (AND) and || (OR) operators is sufficient to implement all of the methods shown above. You will lose marks for using if statements.

    any help with be greatly appreciate .........

    Thx
    Tom
     
  2. korrupshun

    korrupshun New Member

    Joined:
    Sep 8, 2004
    Messages:
    389
    Likes Received:
    0
    Location:
    YourMommasHouse
    this is a fairly basic assignment, so ill walk you through a FEW of them, as most are damn near identical:

    isOlder(FamilyMember)
    //assuming that all Person objects are in the family, ie there are NO nonfamily members
    //the easiest and sloppiest way to do this is by comparing year variables stored in each person //object (since day and month do not matter)...ie:

    public boolean isOlder(FamilyMember fm){

    return this.birthYear > fm.birthYear;

    }//isOlder


    //One more example, seeing as all of these are nothing more than comparing local variables //to derive solutions, one more should suffice:


    public boolean isBrother(FamilyMember fm){

    return this.getMother() == fm.getMother() || this.getFather() == fm.getFather();

    }//isBrother


    NOTE: after a quick glance, i believe all of these can be done with a SINGLE line like above. This may mean you have to write extra methods or add variables, but it should be fairly easy.

    if you have any more questions, post em up :)
     
  3. WERUreo

    WERUreo Imua!

    Joined:
    Oct 15, 2003
    Messages:
    566
    Likes Received:
    0
    Location:
    Daytona Beach, Florida
    Actually, wouldn't it be
    Code:
    public boolean isOlder(FamilyMember fm)
    {
         return this.birthYear < fm.birthYear;
    } //isOlder
    
    If this family member has a greater birth year than the given family member, that would make him/her younger. I know, semantics...

    BTW, what are the class variables and methods for FamilyMember? Just wondering, because the instructions for the isOlder method says to only use the age. Is age one of the class variables for FamilyMember?
     
  4. korrupshun

    korrupshun New Member

    Joined:
    Sep 8, 2004
    Messages:
    389
    Likes Received:
    0
    Location:
    YourMommasHouse
    notice the key phrase "THIS FAMILY MEMBER IS OLDER THAN THE GIVEN", implying that if the THIS object is older then true, else false...so i believe i was correct...also note that it says "AGE IS STRICTLY GREATER....NOT RELATED TO ONE'S BIRTH DAY OR BIRTH MONTH".

    that leads me to believe a storage of birthday by year, month and day as separate variables....or that the age is a variable, i chose the more "complicated" version

    always helps to have multiple eyes on your code tho, no matter how simplistic it is heh, thanks.
     
  5. Shaggy007

    Shaggy007 New Member

    Joined:
    Oct 22, 2003
    Messages:
    901
    Likes Received:
    0
    Location:
    In the Springtime of my youth
    Don't forget to account for the special case(same age).
     
  6. korrupshun

    korrupshun New Member

    Joined:
    Sep 8, 2004
    Messages:
    389
    Likes Received:
    0
    Location:
    YourMommasHouse
    like i said it was quick and sloppy ;) ...though exception usually include if statements.....and i believe twins would PROLLY cover same age......
     
  7. WERUreo

    WERUreo Imua!

    Joined:
    Oct 15, 2003
    Messages:
    566
    Likes Received:
    0
    Location:
    Daytona Beach, Florida
    Yeah, so in order for the THIS object to be older than the FM object, THIS.birthYear needs to be less than fm.birthYear. In other words, THIS is older than FM if THIS was born in a earlier year. Example: I was born in 1975. My fiance was born in 1974. Assume I am THIS. Therefore, this.birthYear = 1975 and fm.birthYear is 1974. So, the expression, (this.birthYear < fm.birthYear) = (1975 < 1974) = false. Therefore, THIS is not older than FM.

    Now, if age was a class variable, then we could say this.age > fm.age and it would be correct. As for the special case of them being the same age, it would still work. If you are the same age, judged solely on the year you were born, then neither one of you would be older than the other, so isOlder would still return false, which would be correct. No need to add any other conditions in.
     
  8. korrupshun

    korrupshun New Member

    Joined:
    Sep 8, 2004
    Messages:
    389
    Likes Received:
    0
    Location:
    YourMommasHouse
    DOH!!! Extreme programming at its finest ;)

    Slap me im stupid heh :slap:

    thanks for pointing that out.
     

Share This Page