diff --git a/src/main/java/com/techreturners/cats/Cat.java b/src/main/java/com/techreturners/cats/Cat.java index e36408f..0d0d427 100644 --- a/src/main/java/com/techreturners/cats/Cat.java +++ b/src/main/java/com/techreturners/cats/Cat.java @@ -1,5 +1,101 @@ package com.techreturners.cats; +import java.util.Random; + interface Cat { + boolean isAsleep(); + void goToSleep(); + void wakeUp(); + String getSetting(); + int getAverageHeight(); + String eat(); + +} + +abstract class GenericCat implements Cat { + private boolean isAsleep = false; // awake by default + private int averageHeight = 0; // in cm + + String setting = "domestic"; + + protected void setAverageHeight(int height) { + averageHeight = height; + } + + protected void setConditioning(String wildOrDomestic) { + setting = wildOrDomestic; + } + + @Override + public boolean isAsleep() { + return isAsleep; + } + + @Override + public void goToSleep() { + isAsleep = true; + } + + @Override + public void wakeUp() { + isAsleep = false; + } + + @Override + public String getSetting() { + return setting; + } + + @Override + public int getAverageHeight() { + return averageHeight; + } + + abstract public String eat(); +} + + +class DomesticCat extends GenericCat { + + Random random = new Random(); + + DomesticCat() { + super.setAverageHeight(23); + super.setConditioning("domestic"); + + } + + public String eat() { + + int x = random.nextInt(10); + if (x < 3) + return ("It will do I suppose"); + // else + return ("Purrrrrrr"); + } + +} + +class LionCat extends GenericCat { + + LionCat() { + super.setAverageHeight(1100); + super.setConditioning("wild"); + } + public String eat() { + return ("Roar!!!!"); + } + +} + +class CheetahCat extends GenericCat { + CheetahCat() { + super.setAverageHeight(12); + super.setConditioning("wild"); + } + public + String eat() { + return ("Zzzzzzz"); + } } diff --git a/src/test/java/com/techreturners/cats/CatTest.java b/src/test/java/com/techreturners/cats/CatTest.java index b5cd1b3..5770a52 100644 --- a/src/test/java/com/techreturners/cats/CatTest.java +++ b/src/test/java/com/techreturners/cats/CatTest.java @@ -2,20 +2,21 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +import java.util.Arrays; public class CatTest { @Test public void checkCatIsAwake() { Cat domesticCat = new DomesticCat(); - assertFalse("Cat should be awake by default", domesticCat.isAsleep()); + assertFalse(domesticCat.isAsleep(), "Cat should be awake by default"); } @Test public void checkCatCanGoToSleep() { Cat domesticCat = new DomesticCat(); domesticCat.goToSleep(); - assertTrue("Cat should be snoozing", domesticCat.isAsleep()); + assertTrue(domesticCat.isAsleep(), "Cat should be snoozing"); } @Test @@ -23,7 +24,7 @@ public void checkCatCanWakep() { Cat domesticCat = new DomesticCat(); domesticCat.goToSleep(); domesticCat.wakeUp(); - assertFalse("Cat should be awake now", domesticCat.isAsleep()); + assertFalse(domesticCat.isAsleep(), "Cat should be awake now" ); } @Test @@ -60,6 +61,8 @@ public void feedTheCheetah() { @Test public void feedTheCat() { Cat domesticCat = new DomesticCat(); - assertEquals("Purrrrrrr", domesticCat.eat()); + + assertTrue(Arrays.asList("Purrrrrrr", "It will do I suppose").contains(domesticCat.eat())); + } }