diff --git a/README.md b/README.md index 433e7ef4..597aa6d7 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ * Consider a system in which * `Eater` can `eat` an `Edible` object. * `NoiseMaker` can `makeNoise` - * `Animal` is a `NoiseMaker` and `Eater` - * `Horse` is an `Animal` and `Rideable` - * `Chicken` is an `Animal` and a `Produce` which `yield` an `EdibleEgg` if `hasBeenFertilized` flag is `false`. + * `com.zipcodewilmington.froilansfarm.Animal` is a `NoiseMaker` and `Eater` + * `Horse` is an `com.zipcodewilmington.froilansfarm.Animal` and `Rideable` + * `Chicken` is an `com.zipcodewilmington.froilansfarm.Animal` and a `Produce` which `yield` an `EdibleEgg` if `hasBeenFertilized` flag is `false`. * `Rider` can `mount` and `dismount` a `Rideable` object. * `Botanist` can `plant` a `Crop` in a `CropRow`. diff --git a/pom.xml b/pom.xml index 69a3b878..4808bf88 100644 --- a/pom.xml +++ b/pom.xml @@ -8,5 +8,28 @@ froilans-farm 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + + junit + junit + 4.12 + test + + + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Animal.java b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Animal.java new file mode 100644 index 00000000..e14d40fa --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Animal.java @@ -0,0 +1,49 @@ +package com.zipcodewilmington.froilansfarm.Animal; + +import com.zipcodewilmington.froilansfarm.Eater; +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.NoiseMaker; + +public class Animal implements NoiseMaker, Eater { + String name; + Integer age; + Integer amountOfFoodEaten; + + public Animal(String name,Integer age,Integer amountOfFoodEaten){ + this.name=name; + this.age=age; + this.amountOfFoodEaten=amountOfFoodEaten; + } +public Animal(){ + this.name=""; + this.age=0; + this.amountOfFoodEaten=0; +} + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public void eat(Edible object) { + + } + + public boolean hasEaten() { + return false; + } + + public String noiseMaker() { + return null; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Barn.java b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Barn.java new file mode 100644 index 00000000..83f67af1 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Barn.java @@ -0,0 +1,35 @@ +package com.zipcodewilmington.froilansfarm.Animal; + +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Barn implements StorageInterface { + List animals; + + public Barn() { + animals = new ArrayList(); + } + + public Integer numberOfAnimals(T animal){ + return animals.size(); + } + + +// public void add(T animal) { +// animals.add(animal); +// } +// +// public void remove(T animal) { +// animals.remove(animal); +// } + + public List getAnimals() { + return animals; + } + + public void setAnimals(List animals) { + this.animals = new ArrayList<>(animals); + } +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Chicken.java b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Chicken.java new file mode 100644 index 00000000..26a37748 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Chicken.java @@ -0,0 +1,33 @@ +package com.zipcodewilmington.froilansfarm.Animal; + +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.Produce; + +public class Chicken extends Animal implements Produce { + Boolean isFertilized=false; + Integer eggs; + +public Chicken(){} + + public void yield(Edible object) { + if(this.isFertilized==true){ + this.eggs+=1; + } + } + + public boolean hasBeenFertilized() { + return false; + } + + public boolean hasBeenHarvested() { + return false; + } + + public String makeNoise(){ + return "Cluck!"; + } + + public void eat(Edible Object){ + + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Farmer.java b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Farmer.java new file mode 100644 index 00000000..62006606 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Farmer.java @@ -0,0 +1,82 @@ +package com.zipcodewilmington.froilansfarm.Animal; + +import com.zipcodewilmington.froilansfarm.Eater; +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.Rideable; +import com.zipcodewilmington.froilansfarm.Rider; +import com.zipcodewilmington.froilansfarm.Vehicle.Botanist; +import com.zipcodewilmington.froilansfarm.crops.Crop; +import com.zipcodewilmington.froilansfarm.crops.CropRow; + +import java.util.ArrayList; +import java.util.List; + +public class Farmer extends Person implements Rider, Eater, Botanist { + CropRow cropRow = new CropRow(); + Integer numberOfRidesTaken; + Integer numberOfCropsPlanted; + Integer numberOfEdiblesEaten; + // List thingsEaten; + String name = "Froilan"; + Rideable vehicle; + + + public Farmer(Integer numberOfRidesTaken, Integer numberOfCropsPlanted, Integer numberOfEdiblesEaten + , String name, ArrayList thingsEaten) { + this.numberOfRidesTaken = numberOfRidesTaken; + this.numberOfCropsPlanted = numberOfCropsPlanted; + this.numberOfEdiblesEaten = numberOfEdiblesEaten; + this.name = name; + //this.thingsEaten = thingsEaten; + + } + + public Farmer() { + } + + public String getName() { + return name; + } + + public void mount(Rideable object) { + this.vehicle=object; + this.numberOfRidesTaken=0; + if (object.hasBeenRiden()) { + numberOfRidesTaken++; + } + } + public Integer getNumberOfRidesTaken() { + return numberOfRidesTaken; + } + + public void dismount(Rideable object) { + this.vehicle=null; + } + + public void eat(Edible object) { + object.isEaten(); + numberOfEdiblesEaten++; + } + + public boolean hasEaten() { + return false; + } + + public void plant(Crop Object) { + cropRow.addCrop(Object); + this.numberOfCropsPlanted = 0; + numberOfCropsPlanted++; + } + + public Integer getNumberOfCropsPlanted() { + return numberOfCropsPlanted; + } + + public void setNumberOfPlants(Integer num) { + this.numberOfCropsPlanted = num; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Horse.java b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Horse.java new file mode 100644 index 00000000..9e9a7eaa --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Horse.java @@ -0,0 +1,30 @@ +package com.zipcodewilmington.froilansfarm.Animal; + +import com.zipcodewilmington.froilansfarm.Rideable; + +public class Horse extends Animal implements Rideable { + + String name; + Integer age; + Integer amountOfFoodEaten; + + public Horse(String name,Integer age,Integer amountOfFoodEaten){ + super(name,age,amountOfFoodEaten); + } + + + public Horse () { + this.name = ""; + this.age = 0; + this.amountOfFoodEaten = 0; + } + + + public boolean hasBeenRiden() { + return false; + } + + public String makeNoise() { + return "Neigh!"; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Person.java b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Person.java new file mode 100644 index 00000000..7fcff08c --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Animal/Person.java @@ -0,0 +1,32 @@ +package com.zipcodewilmington.froilansfarm.Animal; + +public class Person { + String name; + int amountOfFoodEaten; + + public Person(String name,int amountOfFoodEaten){ + this.name=name; + this.amountOfFoodEaten=amountOfFoodEaten; + } + + public Person(){ + this.name=""; + this.amountOfFoodEaten=0; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAmountOfFoodEaten() { + return amountOfFoodEaten; + } + + public void setAmountOfFoodEaten(int amountOfFoodEaten) { + this.amountOfFoodEaten = amountOfFoodEaten; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Eater.java b/src/main/java/com/zipcodewilmington/froilansfarm/Eater.java new file mode 100644 index 00000000..d8fd7aab --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Eater.java @@ -0,0 +1,8 @@ +package com.zipcodewilmington.froilansfarm; + +public interface Eater { + + void eat(Edible object); + + boolean hasEaten(); +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Edible.java b/src/main/java/com/zipcodewilmington/froilansfarm/Edible.java new file mode 100644 index 00000000..35ebe179 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Edible.java @@ -0,0 +1,7 @@ +package com.zipcodewilmington.froilansfarm; + +public interface Edible { + + boolean isEaten(); + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/MainApplication.java b/src/main/java/com/zipcodewilmington/froilansfarm/MainApplication.java index fd743ffc..0cac6426 100644 --- a/src/main/java/com/zipcodewilmington/froilansfarm/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/froilansfarm/MainApplication.java @@ -1,8 +1,42 @@ package com.zipcodewilmington.froilansfarm; +import com.zipcodewilmington.froilansfarm.storage.ChickenCoop; +import com.zipcodewilmington.froilansfarm.storage.Farm; +import com.zipcodewilmington.froilansfarm.storage.Stable; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; + /** * Created by leon on 2/26/18. */ -public class MainApplication { + public class MainApplication { + //holds a list of the days of the week + //each day is its own class + //each day class has its own "Runnable" schedule + //make fertilize method + //make check fertilization method (hasBeenFertilized) + //potentially make Farmer abstract so that Froilan and Froilanda can both be declared new Farmers + // + public static void main(String[] args) { + Farm farm = new Farm<>(); + Stable stable1= new Stable(); + Stable stable2 = new Stable(); + Stable stable3 = new Stable(); + farm.add(stable1); + farm.add(stable2); + farm.add(stable3); + ChickenCoop coop1 = new ChickenCoop(); + ChickenCoop coop2= new ChickenCoop(); + ChickenCoop coop3= new ChickenCoop(); + ChickenCoop coop4 = new ChickenCoop(); + farm.add(coop1); + farm.add(coop2); + farm.add(coop3); + farm.add(coop4); + int size = farm.amount(); + int coops = farm.getAmountofCoops(); + + System.out.println(size); + System.out.println(coops); } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/NoiseMaker.java b/src/main/java/com/zipcodewilmington/froilansfarm/NoiseMaker.java new file mode 100644 index 00000000..50523652 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/NoiseMaker.java @@ -0,0 +1,6 @@ +package com.zipcodewilmington.froilansfarm; + +public interface NoiseMaker { + + String noiseMaker (); +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Produce.java b/src/main/java/com/zipcodewilmington/froilansfarm/Produce.java new file mode 100644 index 00000000..04f4157c --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Produce.java @@ -0,0 +1,11 @@ +package com.zipcodewilmington.froilansfarm; + +public interface Produce { + + + void yield(Edible object); + + boolean hasBeenFertilized(); + + boolean hasBeenHarvested(); +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Rideable.java b/src/main/java/com/zipcodewilmington/froilansfarm/Rideable.java new file mode 100644 index 00000000..a63a49e7 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Rideable.java @@ -0,0 +1,6 @@ +package com.zipcodewilmington.froilansfarm; + +public interface Rideable { + + boolean hasBeenRiden(); +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Rider.java b/src/main/java/com/zipcodewilmington/froilansfarm/Rider.java new file mode 100644 index 00000000..66534ac4 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Rider.java @@ -0,0 +1,8 @@ +package com.zipcodewilmington.froilansfarm; + +public interface Rider { + + void mount(Rideable object); + + void dismount(Rideable object); +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Aircraft.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Aircraft.java new file mode 100644 index 00000000..80ed677d --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Aircraft.java @@ -0,0 +1,8 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + +import com.zipcodewilmington.froilansfarm.Vehicle.Vehicle; + +public interface Aircraft extends Vehicle { + + void fly(int distance); +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Botanist.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Botanist.java new file mode 100644 index 00000000..284bfae7 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Botanist.java @@ -0,0 +1,10 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + +import com.zipcodewilmington.froilansfarm.crops.Crop; + +public interface Botanist { + void plant(Crop Object); + + void setNumberOfPlants(Integer num); + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/CropDuster.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/CropDuster.java new file mode 100644 index 00000000..d86bdf09 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/CropDuster.java @@ -0,0 +1,78 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + + +import com.zipcodewilmington.froilansfarm.crops.Crop; +import com.zipcodewilmington.froilansfarm.crops.CropRow; + +public class CropDuster extends FarmVehicle implements Aircraft { + + public boolean toBeFertilized; + public int numOfCropRows; + public int numOfCropFert; + + public CropDuster(boolean toBeFertilized, int numOfCropRows, int numOfCropFert) { + this.toBeFertilized = toBeFertilized; + this.numOfCropRows = numOfCropRows; + this.numOfCropFert = numOfCropFert; + } + + public boolean isToBeFertilized() { + return toBeFertilized; + } + + public void setToBeFertilized(boolean toBeFertilized) { + this.toBeFertilized = toBeFertilized; + } + + public int getNumOfCropFert() { + return numOfCropFert; + } + + public void setNumOfCropFert(int numOfCropFert) { + this.numOfCropFert = numOfCropFert; + } + + + public void setNumOfCropRows(int numOfCropRows) { + this.numOfCropRows = numOfCropRows; + + } + + public int getNumOfCropRows() { + return this.numOfCropRows; + } + + public void setNumOfFertCrop(int numOfCropFert) { + this.numOfCropFert = numOfCropFert; + } + + public int getNumOfFertCrop() { + return this.numOfCropFert; + } + + public boolean needsToBeFertilized(CropRow cropRow) { + for (Crop crop : cropRow.getCropRow()) { + if (crop.hasBeenFertilized()==false){ + return true; + } + } + return false; + } + + @Override + public void fly(int distance) { + + } + + @Override + public String noiseMaker() { + return "Ppbd Ppbd"; + } + + @Override + public boolean hasBeenRiden() { + return false; + } + + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/FarmVehicle.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/FarmVehicle.java new file mode 100644 index 00000000..90cfef65 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/FarmVehicle.java @@ -0,0 +1,41 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + +public class FarmVehicle implements Vehicle{ + String onFarm; + String offFarm; + String location; + + public FarmVehicle(String onFarm, String offFarm, String location) { + this.onFarm = onFarm; + this.offFarm = offFarm; + this.location = location; + } + + public FarmVehicle() { + + } + + public void setLocation(String expected){ this.location=location; + } + + public String getLocation() { + return this.location; + } + + public Boolean operation(String location){ + boolean canOperate; + if(location==onFarm){ + return canOperate=true; + }return canOperate=false; + } + + @Override + public String noiseMaker() { + return null; + } + + @Override + public boolean hasBeenRiden() { + return false; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Pilot.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Pilot.java new file mode 100644 index 00000000..346d8b89 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Pilot.java @@ -0,0 +1,22 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + +import com.zipcodewilmington.froilansfarm.Animal.Person; +import com.zipcodewilmington.froilansfarm.Rideable; +import com.zipcodewilmington.froilansfarm.Rider; + +public class Pilot extends Person implements Rider { + public Pilot() { + super(); + } + + + @Override + public void mount(Rideable object) { + + } + + @Override + public void dismount(Rideable object) { + + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Tractor.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Tractor.java new file mode 100644 index 00000000..097f381c --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Tractor.java @@ -0,0 +1,51 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + +import com.zipcodewilmington.froilansfarm.crops.Crop; +import com.zipcodewilmington.froilansfarm.crops.CropRow; + +public class Tractor extends FarmVehicle { + boolean toBeHarvested; + int numOfFertCrop; + int numOfHarvCrop; + + public Tractor(boolean toBeHarvested, int numOfFertCrop, int numOfHarvCrop) { + super(); + this.toBeHarvested = toBeHarvested; + this.numOfFertCrop = numOfFertCrop; + this.numOfHarvCrop = numOfHarvCrop; + } + + public boolean isToBeHarvested() { + return toBeHarvested; + } + + public void setToBeHarvested(boolean toBeHarvested) { + this.toBeHarvested = toBeHarvested; + } + + public void setNumOfFertCrop(int numOfFertCrop) { + this.numOfFertCrop = numOfFertCrop; + } + + public void setNumOfHarvCrop(int numOfHarvCrop) { + this.numOfHarvCrop = numOfHarvCrop; + } + + public int getNumOfHarvCrop() { + return this.numOfHarvCrop; + } + + public int getNumOfFertCrop() { + return this.numOfFertCrop; + } + + public boolean needsToBeHarvested(CropRow cropRow) { + for (Crop crop : cropRow.getCropRow()) { + if (crop.hasBeenHarvested() == false) { + return true; + } + } + return false; + } +} + diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Vehicle.java b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Vehicle.java new file mode 100644 index 00000000..6d227a9e --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Vehicle.java @@ -0,0 +1,8 @@ +package com.zipcodewilmington.froilansfarm.Vehicle; + +import com.zipcodewilmington.froilansfarm.NoiseMaker; +import com.zipcodewilmington.froilansfarm.Rideable; + +public interface Vehicle extends Rideable, NoiseMaker { + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/crops/CornPlant.java b/src/main/java/com/zipcodewilmington/froilansfarm/crops/CornPlant.java new file mode 100644 index 00000000..87179c85 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/crops/CornPlant.java @@ -0,0 +1,16 @@ +package com.zipcodewilmington.froilansfarm.crops; + +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.Produce; + +public class CornPlant extends Crop{ + + public CornPlant(Integer numOfEdiblesYielded, Integer numOfCropsHarvested, Integer numOfEdiblesEaten) { + super(numOfEdiblesYielded, numOfCropsHarvested, numOfEdiblesEaten); + } + + public CornPlant() { + super(); + } + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/crops/Crop.java b/src/main/java/com/zipcodewilmington/froilansfarm/crops/Crop.java new file mode 100644 index 00000000..227916f4 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/crops/Crop.java @@ -0,0 +1,69 @@ +package com.zipcodewilmington.froilansfarm.crops; + +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.Produce; + +public abstract class Crop implements Produce { + Integer numOfEdiblesYielded; //once fertilized + Integer numOfEdiblesHarvested; //once harvested + Integer numOfEdiblesEaten; //decrement if eaten + Boolean hasBeenFertilized; + Boolean hasBeenHarvested; + + + public Crop(Integer numOfYield, Integer numOfCropsHarvested, Integer numOfEdiblesLeft, Boolean hasBeenFertilized, Boolean hasBeenHarvested) { + this.numOfEdiblesYielded = numOfYield; + this.numOfEdiblesHarvested = numOfCropsHarvested; + this.numOfEdiblesEaten = numOfEdiblesLeft; + this.hasBeenFertilized = hasBeenFertilized; + this.hasBeenHarvested = hasBeenHarvested; + } + + public Crop(Integer numOfYield, Integer numOfCropsHarvested, Integer numOfEdiblesLeft) { + this(numOfYield, numOfCropsHarvested, numOfEdiblesLeft, false, false); + } + + public Crop() { + this(0, 0, 0); + } + + public void fertilize() { + this.hasBeenFertilized = true; + } + + public void harvest() { + this.hasBeenHarvested = true; + } + + public Integer getNumOfEdiblesYielded() { + return numOfEdiblesYielded; + } + + + public Integer getNumberofHarvest() { + if (hasBeenHarvested) { + return numOfEdiblesYielded; + } + return numOfEdiblesHarvested; + } + + public void yield(Edible edible) { + if (hasBeenFertilized) { + numOfEdiblesYielded++; + } else { + throw new UnsupportedOperationException("Must be fertilized first!"); + } + } + + public boolean hasBeenFertilized() { + return hasBeenFertilized; + } + + public boolean hasBeenHarvested() { + return hasBeenHarvested; + } + + public Integer getFoodToEat() { + return numOfEdiblesHarvested - numOfEdiblesEaten; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/crops/CropRow.java b/src/main/java/com/zipcodewilmington/froilansfarm/crops/CropRow.java new file mode 100644 index 00000000..f2fc51c2 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/crops/CropRow.java @@ -0,0 +1,48 @@ +package com.zipcodewilmington.froilansfarm.crops; + +import com.zipcodewilmington.froilansfarm.Edible; + +import java.util.ArrayList; +import java.util.List; + +public class CropRow { + List cropRow; + + + public CropRow(List cropRow) { + this.cropRow = cropRow; + + } + + public CropRow() { + this.cropRow = new ArrayList<>(); + } + + public int getNumberofCropsPlanted() {return cropRow.size();} + + public List getCropRow() { + return cropRow; + } + + public void addCrop(Crop crop, Integer numberOfCrops){ + for (int i = 0; i < numberOfCrops; i++) { + cropRow.add(crop); + } + } + public void addCrop(Crop crop){ + cropRow.add(crop); + } + + public void removeCrop(Crop crop) { + cropRow.remove(crop); + } + + public int getNumberOfEdibles() { + int sum = 0; + for (Crop crop : cropRow) { + sum += crop.getNumOfEdiblesYielded(); + } + return sum; + } + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/crops/EarOfCorn.java b/src/main/java/com/zipcodewilmington/froilansfarm/crops/EarOfCorn.java new file mode 100644 index 00000000..2f56ba98 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/crops/EarOfCorn.java @@ -0,0 +1,10 @@ +package com.zipcodewilmington.froilansfarm.crops; + +import com.zipcodewilmington.froilansfarm.Edible; + +public class EarOfCorn implements Edible { + @Override + public boolean isEaten() { + return false; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/crops/Tomato.java b/src/main/java/com/zipcodewilmington/froilansfarm/crops/Tomato.java new file mode 100644 index 00000000..f4ed5953 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/crops/Tomato.java @@ -0,0 +1,10 @@ +package com.zipcodewilmington.froilansfarm.crops; + +import com.zipcodewilmington.froilansfarm.Edible; + +public class Tomato implements Edible { + @Override + public boolean isEaten() { + return false; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/crops/TomatoPlant.java b/src/main/java/com/zipcodewilmington/froilansfarm/crops/TomatoPlant.java new file mode 100644 index 00000000..502ac8ca --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/crops/TomatoPlant.java @@ -0,0 +1,24 @@ +package com.zipcodewilmington.froilansfarm.crops; + +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.Produce; + +public class TomatoPlant extends Crop{ + public TomatoPlant(Integer numOfEdiblesYielded, Integer numOfCropsHarvested, Integer numOfCropsFertilized) { + super(numOfEdiblesYielded, numOfCropsHarvested, numOfCropsFertilized); + } + + public TomatoPlant(Integer numberOfTomatoes) { + super(numberOfTomatoes,0,0); + } + + public TomatoPlant() { + super(); + } + + public Edible getYield(){ + return new Tomato(); + } + + +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/storage/ChickenCoop.java b/src/main/java/com/zipcodewilmington/froilansfarm/storage/ChickenCoop.java new file mode 100644 index 00000000..5fc89796 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/storage/ChickenCoop.java @@ -0,0 +1,38 @@ +package com.zipcodewilmington.froilansfarm.storage; + + +import com.zipcodewilmington.froilansfarm.Animal.Barn; +import com.zipcodewilmington.froilansfarm.Animal.Chicken; + + + +import java.util.ArrayList; +import java.util.List; + +public class ChickenCoop extends Barn { + + List listOfChicken; + + public ChickenCoop () { + listOfChicken = new ArrayList<>(); + } + + @Override + public void add(Object thingYouAreStoring) { + listOfChicken.add((Chicken) thingYouAreStoring); + } + + @Override + public void remove(Object thingYouAreStoring) { + listOfChicken.remove(thingYouAreStoring); + } + + @Override + public int amount(Object thingYouAreStoring) { + return listOfChicken.size(); + } + + public Integer getListOfChicken() { + return listOfChicken.size(); + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/storage/Farm.java b/src/main/java/com/zipcodewilmington/froilansfarm/storage/Farm.java new file mode 100644 index 00000000..4d321047 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/storage/Farm.java @@ -0,0 +1,56 @@ +package com.zipcodewilmington.froilansfarm.storage; + +import com.zipcodewilmington.froilansfarm.Vehicle.Vehicle; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; + +import java.util.ArrayList; +import java.util.List; + +public class Farm { + + List farm = new ArrayList<>(); + Field field; + List vehicles = new ArrayList<>(); + + public Farm () { + // This is a test, nerd + } + + + public void add(StorageInterface storage) { + farm.add(storage); + + } + + + public void remove( StorageInterface storage) { + farm.remove(storage); + } + + + public int amount() { + return farm.size(); + } + + public int getAmountofCoops(){ + int numOfOccurences = 0; + for (StorageInterface s : farm) { + if (s instanceof ChickenCoop){ + numOfOccurences++; + } + + } + return numOfOccurences; + } + + public int getAmountofStable(){ + int numOfOccurences = 0; + for (StorageInterface s : farm) { + if (s instanceof Stable){ + numOfOccurences++; + } + + } + return numOfOccurences; + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/storage/Field.java b/src/main/java/com/zipcodewilmington/froilansfarm/storage/Field.java new file mode 100644 index 00000000..3b1c6102 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/storage/Field.java @@ -0,0 +1,34 @@ +package com.zipcodewilmington.froilansfarm.storage; + +import com.zipcodewilmington.froilansfarm.crops.CropRow; + +import java.util.ArrayList; +import java.util.List; + +public class Field implements StorageInterface { + + List listOfCropRow; + + public Field () { + this.listOfCropRow = new ArrayList<>(); + } + + @Override + public void add(Object thingYouAreStoring) { + listOfCropRow.add((CropRow) thingYouAreStoring); + } + + @Override + public void remove(Object thingYouAreStoring) { + listOfCropRow.remove(thingYouAreStoring); + } + + @Override + public int amount(Object thingYouAreStoring) { + return listOfCropRow.size(); + } + + public Integer getListOfCropRow() { + return listOfCropRow.size(); + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/storage/Stable.java b/src/main/java/com/zipcodewilmington/froilansfarm/storage/Stable.java new file mode 100644 index 00000000..d5fc2cba --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/storage/Stable.java @@ -0,0 +1,37 @@ +package com.zipcodewilmington.froilansfarm.storage; + + +import com.zipcodewilmington.froilansfarm.Animal.Barn; +import com.zipcodewilmington.froilansfarm.Animal.Horse; + + +import java.util.ArrayList; +import java.util.List; + +public class Stable extends Barn { + + List listOfHorses; + + public Stable () { + listOfHorses = new ArrayList<>(); + } + + @Override + public void add(Object thingYouAreStoring) { + listOfHorses.add((Horse) thingYouAreStoring); + } + + @Override + public void remove(Object thingYouAreStoring) { + listOfHorses.remove(thingYouAreStoring); + } + + @Override + public int amount(Object thingYouAreStoring) { + return listOfHorses.size(); + } + + public Integer getListOfHorses () { + return listOfHorses.size(); + } +} diff --git a/src/main/java/com/zipcodewilmington/froilansfarm/storage/StorageInterface.java b/src/main/java/com/zipcodewilmington/froilansfarm/storage/StorageInterface.java new file mode 100644 index 00000000..4ccf5612 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/froilansfarm/storage/StorageInterface.java @@ -0,0 +1,12 @@ +package com.zipcodewilmington.froilansfarm.storage; + +import java.lang.reflect.Type; + +public interface StorageInterface { + + void add(TypeToStore thingYouAreStoring); + + void remove(TypeToStore thingYouAreStoring); + + int amount(TypeToStore thingYouAreStoring); +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/AnimalTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/AnimalTest.java new file mode 100644 index 00000000..03daf4d1 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/AnimalTest.java @@ -0,0 +1,88 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; +import com.zipcodewilmington.froilansfarm.Animal.Animal; +import org.junit.Test; +import org.junit.Assert; +public class AnimalTest { + + @Test + public void nullaryConstructorTest(){ + Animal animal=new Animal(); + //when + int actual=animal.getAge(); + + //then + Assert.assertEquals(0,actual); + } + //given + + @Test + public void nullaryConstructorTest2(){ + Animal animal=new Animal(); + //when + String actual=animal.getName(); + + //then + Assert.assertEquals("",actual); + } + + @Test + public void constructorTest(){ + String name = "Sitara"; + Integer age = 20; + Integer amountOfFoodEaten = 2; + Animal animal=new Animal(name,age,amountOfFoodEaten); + //when + String actual=animal.getName(); + + //then + Assert.assertEquals("Sitara",actual); + } + @Test + public void getAgeTest(){ + String name = "Sitara"; + Integer age = 20; + Integer amountOfFoodEaten = 2; + Animal animal=new Animal(name,age,amountOfFoodEaten); + //when + Integer actual=animal.getAge(); + + //then + Assert.assertEquals(age,actual); + } + + @Test + public void setAgeTest(){ + String name = "Sitara"; + Integer age = 20; + Integer expected = 24; + Integer amountOfFoodEaten = 2; + Animal animal=new Animal(name,age,amountOfFoodEaten); + animal.setAge(24); + //when + Integer actual=animal.getAge(); + + //then + Assert.assertEquals(expected,actual); + } + + @Test + public void setNameTest(){ + String name = "Sutara"; + Integer age = 20; + String expected = "Sitara"; + Integer amountOfFoodEaten = 2; + Animal animal=new Animal(name,age,amountOfFoodEaten); + animal.setName(expected); + //when + String actual=animal.getName(); + + //then + Assert.assertEquals(expected,actual); + } + + + + + + +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/BarnTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/BarnTest.java new file mode 100644 index 00000000..547bec03 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/BarnTest.java @@ -0,0 +1,81 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; + +import com.zipcodewilmington.froilansfarm.Animal.Animal; +import com.zipcodewilmington.froilansfarm.Animal.Barn; +import com.zipcodewilmington.froilansfarm.Animal.Chicken; +import com.zipcodewilmington.froilansfarm.Animal.Horse; +import com.zipcodewilmington.froilansfarm.storage.ChickenCoop; +import com.zipcodewilmington.froilansfarm.storage.Stable; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class BarnTest { + + @Test + public void numberOfAnimalsTest() { + Barn barn = new ChickenCoop(); + List animals = new ArrayList(); + ; + + //List animals = new ArrayList<>(); + animals.add((T) "chicken"); + animals.add((T) "horse"); + animals.add((T) "chick"); + Integer expected = 3; + barn.setAnimals(animals); + Assert.assertEquals(expected, barn.numberOfAnimals(animals)); + } + + @Test + public void addTest() { + Barn barn = new ChickenCoop(); + List animals = new ArrayList<>(); + animals.add("chicken"); + barn.setAnimals(animals); + //animals.toArray(); + Assert.assertEquals("chicken", barn.getAnimals().get(0)); + + } + + @Test + public void removeTest() { + Barn barn = new Stable(); + List animals = new ArrayList<>(); + Animal horse = new Horse(); + Animal horse2 = new Horse(); + + animals.add(horse2); + animals.add(horse); + + barn.setAnimals(animals); + + barn.getAnimals().remove(horse); + + Assert.assertEquals(1, barn.getAnimals().size()); + } + + @Test + public void testGetAnimals() { + Barn barn = new Stable(); + List animals = new ArrayList<>(); + animals.add("chicken"); + animals.add("horse"); + barn.setAnimals(animals); + + Assert.assertEquals("chicken", barn.getAnimals().get(0)); + } + + @Test + public void testSetAnimals() { + Barn barn = new ChickenCoop(); + List animals = new ArrayList<>(); + animals.add("chicken"); + animals.add("horse"); + barn.setAnimals(animals); + + Assert.assertEquals("horse", barn.getAnimals().get(1)); + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/ChickenTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/ChickenTest.java new file mode 100644 index 00000000..510a896a --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/ChickenTest.java @@ -0,0 +1,58 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; + +import com.zipcodewilmington.froilansfarm.Animal.Animal; +import com.zipcodewilmington.froilansfarm.Animal.Chicken; +import com.zipcodewilmington.froilansfarm.Edible; +import com.zipcodewilmington.froilansfarm.Produce; +import org.junit.Assert; +import org.junit.Test; + +public class ChickenTest { + + @Test + public void instanceOfAnimal () { + Chicken chicken = new Chicken(); + + Assert.assertTrue(chicken instanceof Animal); + } + + @Test + public void instanceOfProduce () { + Chicken chicken = new Chicken(); + + Assert.assertTrue(chicken instanceof Produce); + } + + @Test + public void hasBeenFertilisedTest(){ + Chicken chicken =new Chicken(); + Assert.assertFalse(chicken.hasBeenFertilized()); + } + @Test + public void hasBeenHarvestedTest(){ + Chicken chicken =new Chicken(); + Assert.assertFalse(chicken.hasBeenHarvested()); + } + + @Test + public void yieldTest(){ + Chicken chicken =new Chicken(); + Edible object = new Edible() { + @Override + public boolean isEaten() { + return false; + } + }; + chicken.yield(object); + Assert.assertTrue(true); + } + + @Test + public void makeNoiseTest(){ + Chicken chicken = new Chicken(); + String noise="Cluck!"; + String actual= chicken.makeNoise(); + Assert.assertEquals("Cluck!",actual); + } + +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/FarmerTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/FarmerTest.java new file mode 100644 index 00000000..ebd85555 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/FarmerTest.java @@ -0,0 +1,56 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; + +import com.zipcodewilmington.froilansfarm.Animal.Farmer; +import com.zipcodewilmington.froilansfarm.Rideable; +import com.zipcodewilmington.froilansfarm.crops.CornPlant; +import com.zipcodewilmington.froilansfarm.crops.Crop; +import com.zipcodewilmington.froilansfarm.crops.CropRow; +import org.junit.Assert; +import org.junit.Test; + +public class FarmerTest { + @Test + public void constructorTest(){ + Farmer farmer= new Farmer(); + String actualName="Froilan"; + Assert.assertEquals(farmer.getName(),actualName); + } + @Test + public void hasEatenTest(){ + Farmer farmer= new Farmer(); + Boolean actual=false; + Assert.assertFalse(farmer.hasEaten()); + } + + @Test + public void plantTest(){ + Farmer farmer= new Farmer(); + CropRow cropRow=new CropRow(); + Integer numberOfCrops=0; + Crop crop=new CornPlant(); +Integer expected=1; +// cropRow.addCrop(crop); +farmer.plant(crop); + Assert.assertEquals(expected,farmer.getNumberOfCropsPlanted()); + + } + + @Test + public void mountTest(){ + Farmer farmer= new Farmer(); + Integer expected = 1; + + Rideable vehicle = new Rideable() { + @Override + public boolean hasBeenRiden() { + return true; + } + }; + farmer.mount(vehicle); + + Assert.assertEquals(expected,farmer.getNumberOfRidesTaken()); + + } + +} + diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/HorseTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/HorseTest.java new file mode 100644 index 00000000..9b1e34c8 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/HorseTest.java @@ -0,0 +1,29 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; + +import com.zipcodewilmington.froilansfarm.Animal.Horse; +import org.junit.Assert; +import org.junit.Test; + +public class HorseTest { + @Test + public void makeNoiseTest() { + Horse horse= new Horse(null,null,null); + String noise = "Neigh!"; + String actual = horse.makeNoise(); + Assert.assertEquals("Neigh!", actual); + } + + @Test + public void hadBeenRiddenTest(){ + Horse horse =new Horse(null,null,null); + Boolean actual=false; + Assert.assertEquals(horse.hasBeenRiden(),actual); + } + + @Test + public void constructorTest(){ + Horse horse= new Horse("robert",10,null); + String actual="robert"; + Assert.assertEquals(horse.getName(),actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/PersonTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/PersonTest.java new file mode 100644 index 00000000..b03166bd --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/PersonTest.java @@ -0,0 +1,58 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; + + +import com.zipcodewilmington.froilansfarm.Animal.Person; +import org.junit.Assert; +import org.junit.Test; + +public class PersonTest { + @Test + public void constructorTest(){ + Person person =new Person(); + String actualName=""; + Integer amountOfFoodEaten; + + String expectedName=person.getName(); + //then + Assert.assertEquals(expectedName,actualName); + } + + @Test + public void constructorTest2(){ + Person person =new Person(); + + Integer actualAmountOfFoodEaten=0; + + Integer expectedAmount=person.getAmountOfFoodEaten(); + //then + Assert.assertEquals(expectedAmount,actualAmountOfFoodEaten); + } + + @Test + public void setNameTest(){ + String name = "Sutara"; + String expected = "Sitara"; + Integer amountOfFoodEaten = 2; + Person person=new Person(name,amountOfFoodEaten); + person.setName(expected); + //when + String actual=person.getName(); + + //then + Assert.assertEquals(expected,actual); + } + + @Test + public void setAmountOfFoodTest(){ + String name = "Sitara"; + Integer amountOfFoodEaten = 2; + Integer expected = 2; + Person person=new Person(name,amountOfFoodEaten); + person.setAmountOfFoodEaten(expected); + //when + Integer actual=person.getAmountOfFoodEaten(); + + //then + Assert.assertEquals(expected,actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/PilotTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/PilotTest.java new file mode 100644 index 00000000..22e2b100 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/AnimalTest/PilotTest.java @@ -0,0 +1,24 @@ +package com.zipcodewilmington.froilansfarm.AnimalTest; + +import com.zipcodewilmington.froilansfarm.Animal.Person; +import com.zipcodewilmington.froilansfarm.Rider; +import com.zipcodewilmington.froilansfarm.Vehicle.Pilot; +import org.junit.Assert; +import org.junit.Test; + +public class PilotTest { + + @Test + public void instanceOfPerson () { + Pilot p = new Pilot(); + + Assert.assertTrue(p instanceof Person); + } + + @Test + public void instanceOfRider () { + Pilot p = new Pilot(); + + Assert.assertTrue(p instanceof Rider); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/MainApplicationTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/MainApplicationTest.java index 1a971b7f..fc4363be 100644 --- a/src/test/java/com/zipcodewilmington/froilansfarm/MainApplicationTest.java +++ b/src/test/java/com/zipcodewilmington/froilansfarm/MainApplicationTest.java @@ -1,7 +1,32 @@ package com.zipcodewilmington.froilansfarm; +import com.zipcodewilmington.froilansfarm.storage.Farm; +import com.zipcodewilmington.froilansfarm.storage.Stable; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; +import org.junit.Assert; +import org.junit.Test; + /** * Created by leon on 2/26/18. */ public class MainApplicationTest { + + @Test + public void addStorageTest(){ + //given + Farm farm = new Farm<>(); + Stable stable1= new Stable(); + Stable stable2 = new Stable(); + Stable stable3 = new Stable(); + int expected = 3; + + //when + farm.add(stable1); + farm.add(stable2); + farm.add(stable3); + int actual = farm.amount(); + + //then + Assert.assertEquals(expected, actual); + } } diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/CropDusterTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/CropDusterTest.java new file mode 100644 index 00000000..b7b2cc97 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/CropDusterTest.java @@ -0,0 +1,90 @@ +package com.zipcodewilmington.froilansfarm.Vehicles; + +import com.zipcodewilmington.froilansfarm.Vehicle.Aircraft; +import com.zipcodewilmington.froilansfarm.Vehicle.CropDuster; +import com.zipcodewilmington.froilansfarm.Vehicle.FarmVehicle; +import com.zipcodewilmington.froilansfarm.Vehicle.Vehicle; +import com.zipcodewilmington.froilansfarm.crops.CropRow; +import org.junit.Assert; +import org.junit.Test; + +public class CropDusterTest { + @Test + public void constructorTest(){ + //given + int numOfCropRows=93; + int numOfFertCrops=32; + boolean toBeFertilized=true; + //when + CropDuster crop = new CropDuster(false, 0, 0); + + //then + Assert.assertNotEquals(numOfCropRows, crop.getNumOfCropRows()); + Assert.assertNotEquals(numOfFertCrops, crop.getNumOfFertCrop()); + Assert.assertNotEquals(toBeFertilized, false); + } + @Test + public void nullaryConstructorTest(){ + //given + boolean expectedFertilizer=false; + int expectedNumOfCrop=895894; + int expectedNumOfFertCrop=4863826; + + //when + CropDuster crop = new CropDuster(true, 0, 0); + //then + Assert.assertNotEquals(expectedNumOfCrop, crop.getNumOfCropRows()); + Assert.assertNotEquals(expectedNumOfFertCrop, crop.getNumOfFertCrop()); + Assert.assertNotEquals(expectedFertilizer, crop.isToBeFertilized()); + + } + @Test + public void getCropsTest1(){ + int expected= 15; + CropDuster crop = new CropDuster(false,0, 0); + crop.setNumOfCropRows(expected); + //when + int actual = crop.getNumOfCropRows(); + //then + Assert.assertEquals(expected, actual); + } + @Test + public void needsToBeFertilizedTest(){ + //given + int cropNum=20; + int fertCrop=4; + boolean expected=true; + CropRow cropRow = new CropRow(); + //when + CropDuster crop =new CropDuster(false, cropNum, fertCrop); + boolean actual= crop.needsToBeFertilized(cropRow); + //then + Assert.assertEquals(expected, actual ); + } + + @Test + public void getFertCropsTest1(){ + int expectedFertCrop = 5; + CropDuster crop = new CropDuster(false, 0, 0); + crop.setNumOfFertCrop(expectedFertCrop); + + int actual = crop.getNumOfFertCrop(); + + Assert.assertEquals(expectedFertCrop, actual); + } + @Test + public void inheritenceTest(){ + CropDuster crop = new CropDuster(false, 0, 0); + Assert.assertTrue(crop instanceof Vehicle); + } + @Test + public void inheritenceTest1(){ + CropDuster crop = new CropDuster(false, 0, 0); + Assert.assertTrue(crop instanceof Aircraft); + } + @Test + public void inheritenceTest2(){ + CropDuster crop = new CropDuster(false, 0, 0); + Assert.assertTrue(crop instanceof FarmVehicle); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/FarmVehicleTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/FarmVehicleTest.java new file mode 100644 index 00000000..ee1a3ec2 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/FarmVehicleTest.java @@ -0,0 +1,33 @@ +package com.zipcodewilmington.froilansfarm.Vehicles; + +import com.zipcodewilmington.froilansfarm.Rideable; +import com.zipcodewilmington.froilansfarm.Vehicle.CropDuster; +import com.zipcodewilmington.froilansfarm.Vehicle.FarmVehicle; +import com.zipcodewilmington.froilansfarm.Vehicle.Vehicle; +import org.junit.Assert; +import org.junit.Test; + +public class FarmVehicleTest { + + @Test + public void nullaryConstructorTest(){ + //given + String expected= ""; + FarmVehicle farm = new FarmVehicle(); + farm.setLocation(expected); + //when + String actual= farm.getLocation(); + //then + Assert.assertEquals(expected, actual); + } + @Test + public void inheritenceCropDustTest(){ + FarmVehicle car = new FarmVehicle(); + Assert.assertTrue(car instanceof Vehicle); + } + @Test + public void inheritenceCropDustTest1(){ + FarmVehicle car = new FarmVehicle(); + Assert.assertTrue(car instanceof Rideable); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/TractorTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/TractorTest.java new file mode 100644 index 00000000..c33f11eb --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/Vehicles/TractorTest.java @@ -0,0 +1,69 @@ +package com.zipcodewilmington.froilansfarm.Vehicles; + +import com.zipcodewilmington.froilansfarm.Vehicle.CropDuster; +import com.zipcodewilmington.froilansfarm.Vehicle.Tractor; +import com.zipcodewilmington.froilansfarm.crops.Crop; +import com.zipcodewilmington.froilansfarm.crops.CropRow; +import org.junit.Assert; +import org.junit.Test; + +public class TractorTest { + + @Test + public void constructorTest() { + //given + int numOfHarvCrops = 93; + int numOfFertCrops = 32; + boolean toBeHarvested = true; + //when + Tractor crop = new Tractor(false, 0, 0); + + //then + Assert.assertNotEquals(numOfHarvCrops, crop.getNumOfHarvCrop()); + Assert.assertNotEquals(numOfFertCrops, crop.getNumOfFertCrop()); + Assert.assertNotEquals(toBeHarvested, false); + } + + @Test + public void nullaryConstructorTest() { + //given + boolean expectedHarvested = true; + int expectedNumOfHarvCrop = 895894; + int expectedNumOfFertCrop = 4863826; + + //when + Tractor crop = new Tractor(false, 0, 0); + //then + Assert.assertNotEquals(expectedNumOfHarvCrop, crop.getNumOfHarvCrop()); + Assert.assertNotEquals(expectedNumOfFertCrop, crop.getNumOfFertCrop()); + Assert.assertNotEquals(expectedHarvested, crop.isToBeHarvested()); + + } + + @Test + public void getCropsTest1() { + int expected = 15; + Tractor crop = new Tractor(false, 0, 0); + crop.setNumOfFertCrop(expected); + //when + int actual = crop.getNumOfFertCrop(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void needsToBeFertilizedTest() { + //given + int cropNum = 20; + int fertCrop = 4; + boolean expected = true; + CropRow cropRow = new CropRow(); + //when + Tractor crop = new Tractor(false, cropNum, fertCrop); + boolean actual = crop.needsToBeHarvested(cropRow); + //then + Assert.assertEquals(expected, actual); + + + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/croptests/CropRowTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/croptests/CropRowTest.java new file mode 100644 index 00000000..3d2b49f4 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/croptests/CropRowTest.java @@ -0,0 +1,133 @@ +package com.zipcodewilmington.froilansfarm.croptests; + +import com.zipcodewilmington.froilansfarm.crops.*; +import org.junit.Assert; +import org.junit.Test; + +public class CropRowTest { + @Test + public void defaultConstructorTest(){ + //given + CropRow testRow = new CropRow(); + + //when + int actual = testRow.getNumberofCropsPlanted(); + + //then + int expected = 0; + Assert.assertEquals(expected, actual); + + } + + @Test + public void defaultConstructorTest2(){ + //given + CropRow testRow = new CropRow(); + + //when + int actual = testRow.getNumberofCropsPlanted(); + + //then + int expected = 0; + Assert.assertEquals(expected, actual); + + } + + @Test + public void addCropTest(){ + //given + CropRow testRow = new CropRow(); + TomatoPlant tomato = new TomatoPlant(0); + + //when + testRow.addCrop(tomato, 2); + int actual = testRow.getNumberofCropsPlanted(); + + //then + int expected = 2; + Assert.assertEquals(expected, actual); + + } + + @Test + public void removeCrop(){ + //given + CropRow testRow = new CropRow(); + TomatoPlant tomato = new TomatoPlant(0); + + //when + testRow.addCrop(tomato); + testRow.removeCrop(tomato); + int actual = testRow.getNumberofCropsPlanted(); + + //then + int expected = 0; + Assert.assertEquals(expected, actual); + } + + @Test + public void getTotalPlants(){ + //given + Crop tomatoPlant = new TomatoPlant(); + Crop cornPlant = new CornPlant(); + tomatoPlant.yield(new Tomato()); + tomatoPlant.yield(new Tomato()); + cornPlant.yield(new EarOfCorn()); + + //when + CropRow testRow = new CropRow(); + testRow.addCrop(tomatoPlant); + testRow.addCrop(cornPlant); + int actual = testRow.getNumberofCropsPlanted(); + + //then + Assert.assertEquals(2, actual); + + } + + @Test + public void getTotalEdibles(){ + //given + Crop tomatoPlant = new TomatoPlant(); + Crop cornPlant = new CornPlant(); + CropRow testRow = new CropRow(); + testRow.addCrop(tomatoPlant); + testRow.addCrop(cornPlant); + tomatoPlant.fertilize(); + cornPlant.fertilize(); + + int expected = 3; + + //when + tomatoPlant.yield(new Tomato()); + tomatoPlant.yield(new Tomato()); + cornPlant.yield(new EarOfCorn()); + int actual = testRow.getNumberOfEdibles(); + + //then + Assert.assertEquals(expected, actual); + + } + + @Test (expected = UnsupportedOperationException.class) + public void getTotalEdiblesExceptionTest() { + //given + Crop tomatoPlant = new TomatoPlant(); + Crop cornPlant = new CornPlant(); + tomatoPlant.yield(new Tomato()); + tomatoPlant.yield(new Tomato()); + cornPlant.yield(new EarOfCorn()); + int expected = 3; + + //when + CropRow testRow = new CropRow(); + testRow.addCrop(tomatoPlant); + testRow.addCrop(cornPlant); + tomatoPlant.fertilize(); + cornPlant.fertilize(); + int actual = testRow.getNumberOfEdibles(); + + //then + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/croptests/CropTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/croptests/CropTest.java new file mode 100644 index 00000000..51b762eb --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/croptests/CropTest.java @@ -0,0 +1,84 @@ +package com.zipcodewilmington.froilansfarm.croptests; + +import com.zipcodewilmington.froilansfarm.crops.CornPlant; +import com.zipcodewilmington.froilansfarm.crops.Crop; +import com.zipcodewilmington.froilansfarm.crops.Tomato; +import com.zipcodewilmington.froilansfarm.crops.TomatoPlant; +import org.junit.Assert; +import org.junit.Test; + +public class CropTest { + + @Test + public void nullaryConstructorTest(){ + //given + Crop tomatoPlant = new TomatoPlant(); + + //when + int actual = tomatoPlant.getNumOfEdiblesYielded(); + + //then + int expected = 0; + Assert.assertEquals(expected, actual); + } + @Test + public void nullaryCornConstructorTest(){ + //given + Crop cornPlant = new CornPlant(); + + //when + int actual = cornPlant.getNumOfEdiblesYielded(); + + //then + int expected = 0; + Assert.assertEquals(expected, actual); + } + + @Test + public void countFertilizedFalseTest(){ + //given + Crop tomatoPlant = new TomatoPlant(); + Tomato tomato = new Tomato(); + int expected = 0; + + //when + tomatoPlant.yield(tomato); + int actual = tomatoPlant.getNumOfEdiblesYielded(); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void countHarvestFalseTest(){ + //given + Crop tomatoPlant = new TomatoPlant(); + Tomato tomato = new Tomato(); + tomatoPlant.yield(tomato); + int expected = 0; + + //when + int actual = tomatoPlant.getNumberofHarvest(); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void AvailableToEatTest(){ + //given + Crop tomatoPlant = new TomatoPlant(); + Tomato tomato = new Tomato(); + int expected = 0; + + //when + tomatoPlant.yield(tomato); + int actual = tomatoPlant.getFoodToEat(); + + //then + Assert.assertEquals(expected, actual); + + + + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/ChickenCoopTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/ChickenCoopTest.java new file mode 100644 index 00000000..cb1f2819 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/ChickenCoopTest.java @@ -0,0 +1,82 @@ +package com.zipcodewilmington.froilansfarm.testStorage; + + +import com.zipcodewilmington.froilansfarm.Animal.Barn; +import com.zipcodewilmington.froilansfarm.Animal.Chicken; +import com.zipcodewilmington.froilansfarm.storage.ChickenCoop; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; +import org.junit.Assert; +import org.junit.Test; + +public class ChickenCoopTest { + + @Test + public void instanceOfBarnTest () { + ChickenCoop cc = new ChickenCoop(); + + Assert.assertTrue(cc instanceof Barn); + } + + @Test + public void implementTest () { + ChickenCoop cc = new ChickenCoop(); + + Assert.assertTrue(cc instanceof StorageInterface); + } + + @Test + public void addTest () { + ChickenCoop cc = new ChickenCoop(); + Chicken chicken = new Chicken(); + Integer expected = 1; + + cc.add(chicken); + Integer actual = cc.getListOfChicken(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeTest () { + ChickenCoop cc = new ChickenCoop(); + Chicken chicken = new Chicken(); + Chicken chicken1 = new Chicken(); + Integer expected = 1; + + cc.add(chicken); + cc.add(chicken1); + cc.remove(chicken); + Integer actual = cc.getListOfChicken(); + + Assert.assertEquals(expected, actual); + // I return an extra chicken, oops + } + + @Test + public void amountTest () { + ChickenCoop cc = new ChickenCoop(); + Chicken chicken = new Chicken(); + Chicken chicken1 = new Chicken(); + Integer expected = 2; + + cc.add(chicken); + cc.add(chicken1); + Integer actual = cc.getListOfChicken(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getChickenCoopTest () { + ChickenCoop cc = new ChickenCoop(); + Chicken chicken = new Chicken(); + Chicken chicken1 = new Chicken(); + Integer expected = 2; + + cc.add(chicken); + cc.add(chicken1); + Integer actual = cc.getListOfChicken(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/FarmTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/FarmTest.java new file mode 100644 index 00000000..96051679 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/FarmTest.java @@ -0,0 +1,96 @@ +package com.zipcodewilmington.froilansfarm.testStorage; + +import com.zipcodewilmington.froilansfarm.Animal.Horse; +import com.zipcodewilmington.froilansfarm.storage.ChickenCoop; +import com.zipcodewilmington.froilansfarm.storage.Farm; +import com.zipcodewilmington.froilansfarm.storage.Stable; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; +import org.junit.Assert; +import org.junit.Test; + +public class FarmTest { + + + @Test + public void addTest () { + Farm farm = new Farm(); + Horse horse = new Horse(); + Horse horse1 = new Horse(); + Integer expected = 2; + + farm.add(horse); + farm.add(horse1); + Integer actual = farm.amount(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeTest () { + Farm farm = new Farm(); + Horse horse = new Horse(); + Horse horse1 = new Horse(); + Integer expected = 1; + + farm.add(horse); + farm.add(horse1); + farm.remove(horse1); + Integer actual = farm.amount(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void amountTest () { + Farm farm = new Farm(); + Horse horse = new Horse(); + Horse horse1 = new Horse(); + Integer expected = 2; + + farm.add(horse); + farm.add(horse1); + Integer actual = farm.amount(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getAmountOfCoopsTest () { + Farm farm = new Farm(); + ChickenCoop chicken = new ChickenCoop(); + ChickenCoop chicken1 = new ChickenCoop(); + Stable stable = new Stable(); + Stable stable1 = new Stable(); + Stable stable2 = new Stable(); + Integer expected = 2; + + farm.add(chicken); + farm.add(chicken1); + farm.add(stable); + farm.add(stable1); + farm.add(stable2); + Integer actual = farm.getAmountofCoops(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getAmountOfStableTest () { + Farm farm = new Farm(); + ChickenCoop chicken = new ChickenCoop(); + ChickenCoop chicken1 = new ChickenCoop(); + Stable stable = new Stable(); + Stable stable1 = new Stable(); + Stable stable2 = new Stable(); + Integer expected = 3; + + farm.add(chicken); + farm.add(chicken1); + farm.add(stable); + farm.add(stable1); + farm.add(stable2); + Integer actual = farm.getAmountofStable(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/FieldTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/FieldTest.java new file mode 100644 index 00000000..ab771ac7 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/FieldTest.java @@ -0,0 +1,60 @@ +package com.zipcodewilmington.froilansfarm.testStorage; + +import com.zipcodewilmington.froilansfarm.crops.CropRow; +import com.zipcodewilmington.froilansfarm.storage.Field; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; +import org.junit.Assert; +import org.junit.Test; + +public class FieldTest { + + @Test + public void implementationTest() { + Field field = new Field(); + Assert.assertTrue(field instanceof StorageInterface); + } + + @Test + public void addTest() { + Field field = new Field(); + CropRow cr = new CropRow(); + CropRow cr2 = new CropRow(); + Integer expected = 2; + + field.add(cr); + field.add(cr2); + Integer actual = field.getListOfCropRow(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeTest() { + Field field = new Field(); + CropRow cr = new CropRow(); + CropRow cr2 = new CropRow(); + Integer expected = 1; + + field.add(cr); + field.add(cr2); + field.remove(cr); + Integer actual = field.getListOfCropRow(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getAmountTest() { + Field field = new Field(); + CropRow cr = new CropRow(); + CropRow cr2 = new CropRow(); + Integer expected = 1; + + field.add(cr); + field.add(cr2); + field.remove(cr); + Integer actual = field.getListOfCropRow(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/StableTest.java b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/StableTest.java new file mode 100644 index 00000000..9231c8f3 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/froilansfarm/testStorage/StableTest.java @@ -0,0 +1,61 @@ +package com.zipcodewilmington.froilansfarm.testStorage; + + +import com.zipcodewilmington.froilansfarm.Animal.Horse; +import com.zipcodewilmington.froilansfarm.storage.Stable; +import com.zipcodewilmington.froilansfarm.storage.StorageInterface; +import org.junit.Assert; +import org.junit.Test; + +public class StableTest { + + @Test + public void implementationTest() { + Stable stable = new Stable(); + Assert.assertTrue(stable instanceof StorageInterface); + } + + @Test + public void addTest() { + Stable stable = new Stable(); + Horse horse = new Horse(); + Horse horse1 = new Horse(); + Integer expected = 2; + + stable.add(horse); + stable.add(horse1); + Integer actual = stable.getListOfHorses(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeTest() { + Stable stable = new Stable(); + Horse horse = new Horse(); + Horse horse1 = new Horse(); + Integer expected = 1; + + stable.add(horse); + stable.add(horse1); + stable.remove(horse); + Integer actual = stable.getListOfHorses(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getListOfHorsesTest() { + Stable stable = new Stable(); + Horse horse = new Horse(); + Horse horse1 = new Horse(); + Integer expected = 1; + + stable.add(horse); + stable.add(horse1); + stable.remove(horse); + Integer actual = stable.getListOfHorses(); + + Assert.assertEquals(expected, actual); + } +}