File tree Expand file tree Collapse file tree 3 files changed +115
-0
lines changed
src/org/launchcode/java/demos Expand file tree Collapse file tree 3 files changed +115
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments