Skip to content

Commit fe0f44d

Browse files
committed
add cat and housecat classes, patch student class so build error doesnt distract
1 parent 8a29291 commit fe0f44d

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.launchcode.java.demos.inheritance;
2+
3+
public abstract class Cat {
4+
5+
private boolean tired = false;
6+
private boolean hungry = false;
7+
private double weight;
8+
9+
// The biological family for all cat species
10+
private String family = "Felidae";
11+
12+
public Cat (double aWeight) {
13+
weight = aWeight;
14+
}
15+
16+
public Cat () {
17+
weight = 13;
18+
}
19+
20+
/**** Getters and Setters ****/
21+
22+
public boolean isTired() {
23+
return tired;
24+
}
25+
26+
public void setTired(boolean aTired) {
27+
tired = aTired;
28+
}
29+
30+
public boolean isHungry() {
31+
return hungry;
32+
}
33+
34+
public void setHungry(boolean aHungry) {
35+
hungry = aHungry;
36+
}
37+
38+
public double getWeight() {
39+
return weight;
40+
}
41+
42+
public void setWeight(double aWeight) {
43+
weight = aWeight;
44+
}
45+
46+
public String getFamily() {
47+
return family;
48+
}
49+
50+
/**** Instance Methods ****/
51+
52+
// A cat is rested and hungry after it sleeps
53+
public void sleep() {
54+
tired = false;
55+
hungry = true;
56+
}
57+
58+
// Eating makes a cat not hungry
59+
public void eat() {
60+
61+
// eating when not hungry makes a cat sleepy
62+
if (!hungry) {
63+
tired = true;
64+
}
65+
66+
hungry = false;
67+
}
68+
69+
public String noise () {
70+
return "Meeeeeeooooowww!";
71+
}
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.launchcode.java.demos.inheritance;
2+
3+
public class HouseCat extends Cat {
4+
private String name;
5+
private String species = "Felis catus";
6+
7+
public HouseCat(String aName, double aWeight) {
8+
super(aWeight);
9+
name = aName;
10+
}
11+
12+
public HouseCat(String aName) {
13+
name = aName;
14+
}
15+
16+
public HouseCat(double aWeight) {
17+
super(aWeight);
18+
}
19+
20+
public boolean isSatisfied() {
21+
return !isHungry() && !isTired();
22+
}
23+
24+
// @Override
25+
// public String noise() {
26+
// return "Hello, my name is " + name + "!";
27+
// }
28+
29+
@Override
30+
public String noise() {
31+
if (isSatisfied()) {
32+
return "Hello, my name is " + name + "!";
33+
} else {
34+
return super.noise(); // prints "Meeeeeeooooowww!"
35+
}
36+
}
37+
38+
public String purr() {
39+
return "I'm a HouseCat";
40+
}
41+
}

src/org/launchcode/java/demos/lsn4school/Student.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public String studentInfo() {
3131
// TODO: Complete the getGradeLevel method here:
3232
public String getGradeLevel() {
3333
// Determine the grade level of the student based on numberOfCredits
34+
// replace this return statement
35+
return "";
3436
}
3537

3638
// TODO: Complete the addGrade method.

0 commit comments

Comments
 (0)