diff --git a/src/com/codefortomorrow/advanced/chapter15/practice/animals/Animal.java b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Animal.java new file mode 100644 index 0000000..2c56942 --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Animal.java @@ -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 +} diff --git a/src/com/codefortomorrow/advanced/chapter15/practice/animals/Cat.java b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Cat.java new file mode 100644 index 0000000..f5148db --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Cat.java @@ -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 + } +} diff --git a/src/com/codefortomorrow/advanced/chapter15/practice/animals/Dog.java b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Dog.java new file mode 100644 index 0000000..471170c --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Dog.java @@ -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 + } +} diff --git a/src/com/codefortomorrow/advanced/chapter15/practice/animals/Zebra.java b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Zebra.java new file mode 100644 index 0000000..857bf0f --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/practice/animals/Zebra.java @@ -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 + } +} diff --git a/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Animal.java b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Animal.java new file mode 100644 index 0000000..b0ae84f --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Animal.java @@ -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) { + 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; + } +} diff --git a/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Cat.java b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Cat.java new file mode 100644 index 0000000..de1c31e --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Cat.java @@ -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()); + } +} diff --git a/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Dog.java b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Dog.java new file mode 100644 index 0000000..9167956 --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Dog.java @@ -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() { + System.out.println(getSound()); + System.out.println(getSound()); + System.out.println(getSound()); + } +} diff --git a/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Zebra.java b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Zebra.java new file mode 100644 index 0000000..f6a00da --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter15/solutions/animals/Zebra.java @@ -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()); + } +}