File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11
11
12
12
###Exercises
13
13
14
- Complete these exercises in ` ClassesAndObjects.java ` . Please use the ` Cat.java ` class to complete these exercises.
14
+ Complete these exercises in ` ClassesAndObjects.java ` . Please use the ` Cat.java ` and ` Person.java ` classes to complete these exercises.
15
15
16
16
####1 . Cool cats
17
17
@@ -42,3 +42,26 @@ Write a method called `makeKitten` that takes 2 Cats as parameters and returns a
42
42
ex: makeKitten(garfield, catwoman) returns a Cat named "GarfieldCatwoman" with age 0
43
43
```
44
44
45
+ ####5 . Adoption
46
+
47
+ 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.
48
+
49
+ ```
50
+ ex: Person jon = Person('Jon');
51
+ adoption(garfield, jon); // Jon is now Garfield's owner!
52
+ ```
53
+
54
+ * Hint: this method does not return anything!*
55
+
56
+ ** Bonus Challenge**
57
+
58
+ If the Cat's name is ` Catwoman ` , don't set the owner, but instead print: "Catwoman will never be anyone's pet!"
59
+
60
+ ####6 . isFree
61
+
62
+ Write a method called ` isFree ` that checks whether or not a Cat has an owner.
63
+
64
+ ```
65
+ ex: isFree(garfield) returns false
66
+ ```
67
+
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ public class Cat {
6
6
private String name ;
7
7
private String favoriteFood ;
8
8
private int age ;
9
+ private Person owner ;
9
10
10
11
public Cat () {
11
12
}
@@ -37,4 +38,12 @@ public String getName() {
37
38
public void setName (String name ) {
38
39
this .name = name ;
39
40
}
41
+
42
+ public void setOwner (Person owner ) {
43
+ this .owner = owner ;
44
+ }
45
+
46
+ public Person getOwner () {
47
+ return owner ;
48
+ }
40
49
}
You can’t perform that action at this time.
0 commit comments