Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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,20 @@
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
) {
// TODO: Complete
}

public void makeSound() {
// TODO: Complete
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.codefortomorrow.advanced.chapter15.practice.animals;

public class Dog extends Animal {

// TODO: Fields

public Dog(
String species,
int age,
String gender,
String sound,
int ageDogYears
) {
// TODO: Complete
}

public void makeSound() {
// TODO: Complete
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
) {
// 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Missing a Javadoc comment.

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,20 @@
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,22 @@
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() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Missing a Javadoc comment.

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,21 @@
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());
}
}