-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
med difficulty practice problem for abstract classes Ch 15 #17
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.codefortomorrow.advanced.chapter15.practice.animals; | ||
|
||
public abstract class Animal { | ||
private String species; | ||
private int age; | ||
private String gender; | ||
private String sound; | ||
|
||
public Animal(String species, int age, String gender, String sound) { | ||
// TODO: Complete | ||
} | ||
|
||
public void grow() { | ||
// TODO: Complete | ||
} | ||
|
||
// TODO: Abstract Methods | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.codefortomorrow.advanced.chapter15.practice.animals; | ||
|
||
public class Cat extends Animal{ | ||
// TODO: Fields | ||
|
||
public Cat (String species, int age, String gender, String sound, String color) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [reviewdog] reported by reviewdog 🐶 |
||
// TODO: Complete | ||
} | ||
|
||
public void makeSound() { | ||
// TODO: Complete | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.codefortomorrow.advanced.chapter15.practice.animals; | ||
|
||
public class Dog extends Animal{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [reviewdog] reported by reviewdog 🐶 |
||
// TODO: Fields | ||
|
||
public Dog (String species, int age, String gender, String sound, int ageDogYears) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [reviewdog] reported by reviewdog 🐶 |
||
// TODO: Complete | ||
} | ||
|
||
public void makeSound() { | ||
// TODO: Complete | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.codefortomorrow.advanced.chapter15.practice.animals; | ||
|
||
public class Zebra extends Animal { | ||
// TODO: Fields | ||
|
||
public Zebra (String species, int age, String gender, String sound, int numStripes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [reviewdog] reported by reviewdog 🐶 |
||
// TODO: Complete | ||
} | ||
|
||
public void makeSound() { | ||
// TODO: Complete | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.codefortomorrow.advanced.chapter15.solutions.animals; | ||
|
||
public abstract class Animal { | ||
private String species; | ||
private int age; | ||
private String gender; | ||
private String sound; | ||
|
||
public Animal(String species, int age, String gender, String sound) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [reviewdog] reported by reviewdog 🐶 |
||
this.species = species; | ||
this.age = age; | ||
this.gender = gender; | ||
this.sound = sound; | ||
} | ||
|
||
public void grow() { | ||
age++; | ||
} | ||
|
||
public abstract void makeSound(); | ||
|
||
public String getSpecies() { | ||
return species; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public String getGender() { | ||
return gender; | ||
} | ||
|
||
public String getSound() { | ||
return sound; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.codefortomorrow.advanced.chapter15.solutions.animals; | ||
|
||
public class Cat extends Animal { | ||
private String color; | ||
|
||
public Cat(String species, int age, String gender, String sound, String color) { | ||
super(species, age, gender, sound); | ||
this.color = color; | ||
} | ||
|
||
public void makeSound() { | ||
System.out.println(getSound()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.codefortomorrow.advanced.chapter15.solutions.animals; | ||
|
||
public class Dog extends Animal { | ||
int ageInDogYears; | ||
|
||
public Dog(String species, int age, String gender, String sound, int ageInDogYears) { | ||
super(species, age, gender, sound); | ||
this.ageInDogYears = ageInDogYears; | ||
} | ||
|
||
public void makeSound() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [reviewdog] reported by reviewdog 🐶 |
||
System.out.println(getSound()); | ||
System.out.println(getSound()); | ||
System.out.println(getSound()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.codefortomorrow.advanced.chapter15.solutions.animals; | ||
|
||
public class Zebra extends Animal { | ||
private int numStripes; | ||
|
||
public Zebra(String species, int age, String gender, String sound, int numStripes) { | ||
super(species, age, gender, sound); | ||
this.numStripes = numStripes; | ||
} | ||
|
||
public void makeSound() { | ||
System.out.println(getSound()); | ||
System.out.println(getSound()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[reviewdog] reported by reviewdog 🐶
WhitespaceAround: '{' is not preceded with whitespace.