Skip to content

Latest commit

 

History

History
71 lines (44 loc) · 2.42 KB

classesobjects.md

File metadata and controls

71 lines (44 loc) · 2.42 KB

#Classes & Objects

###Resources

###Exercises

Complete these exercises in ClassesAndObjects.java. Please use the Cat.java and Person.java classes to complete these exercises.

####1. Cool cats

  1. Create 3 cats named Garfield, Pink Panther, and Catwoman.
  2. Assign each of them a favorite food (Garfield's favorite food should be Lasagna).
  3. Assign each of them an age.

####2. isOlder

Write a method called isOlder that takes 2 Cats as parameters and returns whether or not the first Cat is older than the second.

ex: // if Garfield is 9 years old and Catwoman is 10 years old
    isOlder(garfield, catwoman) returns false

####3. Best Friends

Write a method called makeBestFriends that takes 2 Cats as parameters and sets both of their favorite foods to the same thing.

Hint: this method does not return anything!

####4. Kitten

Write a method called makeKitten that takes 2 Cats as parameters and returns a new Cat with a name that is the combination of the 2 parent Cats' names. The age of the new Cat should be 0.

ex: makeKitten(garfield, catwoman) returns a Cat named "GarfieldCatwoman" with age 0

####5. Adoption

Write a method called adoption that takes 1 Cat and 1 Person as a paramater and sets the Cat's owner to be the Person.

ex: Person jon = Person('Jon');
    adoption(garfield, jon); // Jon is now Garfield's owner!

Hint: this method does not return anything!

Bonus Challenge

If the Cat's name is Catwoman, don't set the owner, but instead print: "Catwoman will never be anyone's pet!"

####6. isFree

Write a method called isFree that checks whether or not a Cat has an owner.

ex: isFree(garfield) returns false

####7. isSibling

Write a method called isSibling that checks whether or not 2 Cats have the same owner.