ThuyKhong před 6 roky
rodič
revize
c3b55cf282

+ 8
- 0
pom.xml Zobrazit soubor

@@ -8,5 +8,13 @@
8 8
     <artifactId>froilans-farm</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
11 19
 
12 20
 </project>

+ 36
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Animals/Animal.java Zobrazit soubor

@@ -0,0 +1,36 @@
1
+package com.zipcodewilmington.froilansfarm.Animals;
2
+
3
+import com.zipcodewilmington.froilansfarm.Eater;
4
+import com.zipcodewilmington.froilansfarm.NoiseMaker;
5
+
6
+import java.util.ArrayList;
7
+import java.util.HashMap;
8
+import java.util.List;
9
+import java.util.Map;
10
+
11
+public class Animal implements NoiseMaker, Eater {
12
+
13
+    private String type;
14
+    private String name;
15
+    protected Map<String, Integer> foodList = new HashMap<String, Integer>();
16
+
17
+    public Animal(){
18
+
19
+    }
20
+
21
+    public Animal(String type, String name){
22
+        this.type = type;
23
+        this.name = name;
24
+    }
25
+
26
+    public Map<String, Integer> eat(String food, int amount){
27
+
28
+        foodList.put(food,amount);
29
+    return foodList;
30
+    }
31
+
32
+    public String makeNoise(String noise){
33
+        return noise;
34
+    }
35
+
36
+}

+ 31
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Animals/Chicken.java Zobrazit soubor

@@ -0,0 +1,31 @@
1
+package com.zipcodewilmington.froilansfarm.Animals;
2
+
3
+import com.zipcodewilmington.froilansfarm.Crop.Produce;
4
+
5
+import java.util.ArrayList;
6
+import java.util.Map;
7
+
8
+public class Chicken extends Animal implements Produce {
9
+
10
+
11
+    public ArrayList<String> yield(boolean hasBeenFertilized, String products){
12
+        ArrayList<String> product = new ArrayList<String>();
13
+
14
+        if (!hasBeenFertilized) {
15
+            product.add(products);
16
+        }
17
+        return product;
18
+    }
19
+
20
+    public String makeNoise(String noise) {
21
+        return noise;
22
+    }
23
+
24
+    public Map<String, Integer> eat(String food, int amount){
25
+
26
+        foodList.put(food,amount);
27
+        return foodList;
28
+    }
29
+
30
+
31
+}

+ 18
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Animals/Horse.java Zobrazit soubor

@@ -0,0 +1,18 @@
1
+package com.zipcodewilmington.froilansfarm.Animals;
2
+
3
+import com.zipcodewilmington.froilansfarm.Animals.Animal;
4
+
5
+import java.util.Map;
6
+
7
+public class Horse extends Animal {
8
+
9
+
10
+
11
+    public Map<String, Integer> eat(String food, int amount){
12
+
13
+        foodList.put(food,amount);
14
+        return foodList;
15
+    }
16
+
17
+
18
+}

+ 15
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Crop/Crop.java Zobrazit soubor

@@ -0,0 +1,15 @@
1
+package com.zipcodewilmington.froilansfarm.Crop;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class Crop implements Produce {
6
+
7
+    //Crop is a Produce which can yield an Edible object depending on its hasBeenHarvested and hasBeenFertilized flag.
8
+    public ArrayList<String> yield(boolean hasBeenFertilized, String products){
9
+        ArrayList<String> product = new ArrayList<String>();
10
+        if (hasBeenFertilized) {
11
+            product.add(products);
12
+        }
13
+        return product;
14
+    }
15
+}

+ 8
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Crop/Produce.java Zobrazit soubor

@@ -0,0 +1,8 @@
1
+package com.zipcodewilmington.froilansfarm.Crop;
2
+
3
+import java.util.ArrayList;
4
+
5
+public interface Produce {
6
+
7
+    ArrayList<String> yield(boolean hasBeenFertilized, String products);
8
+    }

+ 9
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Eater.java Zobrazit soubor

@@ -0,0 +1,9 @@
1
+package com.zipcodewilmington.froilansfarm;
2
+
3
+import java.util.Map;
4
+
5
+public interface Eater {
6
+
7
+
8
+    Map<String, Integer> eat(String food, int amount);
9
+}

+ 12
- 0
src/main/java/com/zipcodewilmington/froilansfarm/MainApplication.java Zobrazit soubor

@@ -1,8 +1,20 @@
1 1
 package com.zipcodewilmington.froilansfarm;
2 2
 
3
+import com.zipcodewilmington.froilansfarm.Animals.Chicken;
4
+import com.zipcodewilmington.froilansfarm.Animals.Horse;
5
+import com.zipcodewilmington.froilansfarm.Person.Person;
6
+
7
+import java.util.ArrayList;
8
+import java.util.List;
9
+
3 10
 /**
4 11
  * Created by leon on 2/26/18.
5 12
  */
6 13
 public class MainApplication {
7 14
 
15
+    private List<Horse> stable = new ArrayList<Horse>();
16
+    private List<Person> farmHouse = new ArrayList<Person>();
17
+    private List<Chicken> chickenCoop = new ArrayList<Chicken>();
18
+    private List<Object> farm = new ArrayList<Object>();
19
+    //Farm stores many Stable, many ChickenCoop, and a single FarmHouse
8 20
 }

+ 6
- 0
src/main/java/com/zipcodewilmington/froilansfarm/NoiseMaker.java Zobrazit soubor

@@ -0,0 +1,6 @@
1
+package com.zipcodewilmington.froilansfarm;
2
+
3
+public interface NoiseMaker {
4
+
5
+    String makeNoise(String noise);
6
+}

+ 31
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Person/Farmer.java Zobrazit soubor

@@ -0,0 +1,31 @@
1
+package com.zipcodewilmington.froilansfarm.Person;
2
+
3
+import com.zipcodewilmington.froilansfarm.Eater;
4
+import com.zipcodewilmington.froilansfarm.Rider;
5
+
6
+import java.util.HashMap;
7
+
8
+public class Farmer extends Person {
9
+    HashMap<String, String> cropList = new HashMap<String, String>();
10
+
11
+
12
+    public HashMap<String, String> plant(String crop, String row){
13
+        cropList.put(crop, row);
14
+        return cropList;
15
+    }
16
+
17
+
18
+    public String mount(Object rideable){
19
+    return "";
20
+    }
21
+
22
+    public String dismount(Object ridable){
23
+    return "";
24
+    }
25
+
26
+    public String harvest(String cropToHarvest, String row) {
27
+        String cropHarvested = "Harvested " + row + " rows of " + cropToHarvest;
28
+
29
+        return cropHarvested;
30
+    }
31
+}

+ 59
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Person/Person.java Zobrazit soubor

@@ -0,0 +1,59 @@
1
+package com.zipcodewilmington.froilansfarm.Person;
2
+
3
+import com.zipcodewilmington.froilansfarm.Eater;
4
+import com.zipcodewilmington.froilansfarm.NoiseMaker;
5
+import com.zipcodewilmington.froilansfarm.Rider;
6
+import com.zipcodewilmington.froilansfarm.Structures.Field;
7
+import com.zipcodewilmington.froilansfarm.Vehicle.FarmVehicle;
8
+
9
+import java.util.*;
10
+
11
+public class Person implements Eater, NoiseMaker, Rider {
12
+
13
+    private Map<String, Integer> foodList = new HashMap<String, Integer>();
14
+
15
+    public Person(){
16
+    }
17
+
18
+    public Map<String, Integer> eat(String food, int amount){
19
+
20
+        foodList.put(food,amount);
21
+        return foodList;
22
+    }
23
+
24
+    public String makeNoise(String noise){
25
+        return "Hello!";
26
+    }
27
+
28
+    public String mount(Object ridable){
29
+    return "";
30
+    }
31
+
32
+    public String dismount(Object ridable){
33
+        return "That was a fun ride!";
34
+    }
35
+
36
+    public String fertilize(String crop){
37
+        FarmVehicle cropDuster = new FarmVehicle("cropDuster", "fertilize");
38
+        return "Used " +  cropDuster.vehicleType + " to " + cropDuster.vehicleFunction + crop;
39
+    }
40
+
41
+    public HashMap<String, String> harvest(HashMap cropPlanted){
42
+        HashMap<String, String> cropHarvested = new HashMap<String, String>();
43
+        if (cropPlanted != null){
44
+            cropHarvested = cropPlanted;
45
+        }
46
+
47
+        return cropHarvested;
48
+    }
49
+
50
+    public HashMap<String, String> plant(String crop, String row){
51
+        Field field = new Field();
52
+        field.setCropRow(row);
53
+
54
+        HashMap<String,String> cropPlanted = new HashMap<String, String>();
55
+
56
+        cropPlanted.put(crop, field.getCropRow());
57
+        return cropPlanted;
58
+    }
59
+}

+ 8
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Rider.java Zobrazit soubor

@@ -0,0 +1,8 @@
1
+package com.zipcodewilmington.froilansfarm;
2
+
3
+public interface Rider {
4
+
5
+    public String mount(Object ridable);
6
+
7
+    public String dismount(Object ridable);
8
+    }

+ 30
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Structures/Farm.java Zobrazit soubor

@@ -0,0 +1,30 @@
1
+package com.zipcodewilmington.froilansfarm.Structures;
2
+
3
+public class Farm {
4
+
5
+    private int farmhouse;
6
+    private int numberOfStable;
7
+    private int noOfChickenCoops;
8
+
9
+    public Farm(int farmhouse, int numberOfStable, int noOfChickenCoops){
10
+        this.farmhouse = farmhouse;
11
+        this.numberOfStable = numberOfStable;
12
+        this.noOfChickenCoops = noOfChickenCoops;
13
+    }
14
+
15
+    public int setNumberOfStable(int numberOfStable){
16
+        return numberOfStable;
17
+    }
18
+
19
+    public int getNumberOfStable(){
20
+        return numberOfStable;
21
+    }
22
+
23
+    public int setNoOfChickenCoops(int noOfChickenCoops){
24
+        return noOfChickenCoops;
25
+    }
26
+
27
+    public int getNoOfChickenCoops() {
28
+        return noOfChickenCoops;
29
+    }
30
+}

+ 23
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Structures/Field.java Zobrazit soubor

@@ -0,0 +1,23 @@
1
+package com.zipcodewilmington.froilansfarm.Structures;
2
+
3
+public class Field {
4
+
5
+    private String cropRow;
6
+
7
+    public Field(){
8
+
9
+    }
10
+
11
+    public Field(String cropRow){
12
+        this.cropRow = cropRow;
13
+    }
14
+
15
+    public void setCropRow(String cropRow){
16
+
17
+        this.cropRow = cropRow;
18
+    }
19
+
20
+    public String getCropRow(){
21
+        return cropRow;
22
+    }
23
+}

+ 6
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/AirCraft.java Zobrazit soubor

@@ -0,0 +1,6 @@
1
+package com.zipcodewilmington.froilansfarm.Vehicle;
2
+
3
+public interface AirCraft {
4
+
5
+    public void fly();
6
+}

+ 15
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/FarmVehicle.java Zobrazit soubor

@@ -0,0 +1,15 @@
1
+package com.zipcodewilmington.froilansfarm.Vehicle;
2
+
3
+import com.zipcodewilmington.froilansfarm.Vehicle.Vehicle;
4
+
5
+public class FarmVehicle extends Vehicle {
6
+
7
+    public String vehicleType;
8
+    public String vehicleFunction;
9
+
10
+    public FarmVehicle(String vehicleType, String vehicleFunction){
11
+        this.vehicleType = vehicleType;
12
+        this.vehicleFunction = vehicleFunction;
13
+    }
14
+
15
+}

+ 7
- 0
src/main/java/com/zipcodewilmington/froilansfarm/Vehicle/Vehicle.java Zobrazit soubor

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.froilansfarm.Vehicle;
2
+
3
+public class Vehicle {
4
+
5
+
6
+
7
+}

+ 159
- 0
src/test/java/com/zipcodewilmington/froilansfarm/TestPerson.java Zobrazit soubor

@@ -0,0 +1,159 @@
1
+package com.zipcodewilmington.froilansfarm;
2
+import com.zipcodewilmington.froilansfarm.Animals.Chicken;
3
+import com.zipcodewilmington.froilansfarm.Animals.Horse;
4
+import com.zipcodewilmington.froilansfarm.Crop.Crop;
5
+import com.zipcodewilmington.froilansfarm.Person.Farmer;
6
+import com.zipcodewilmington.froilansfarm.Person.Person;
7
+import com.zipcodewilmington.froilansfarm.Structures.Field;
8
+import com.zipcodewilmington.froilansfarm.Vehicle.FarmVehicle;
9
+import org.junit.Assert;
10
+import org.junit.Test;
11
+
12
+import java.util.ArrayList;
13
+import java.util.HashMap;
14
+import java.util.Map;
15
+
16
+public class TestPerson {
17
+
18
+    Farmer froilan = new Farmer();
19
+    Farmer freelan = new Farmer();
20
+    Person froilanda = new Person();
21
+    Horse horse = new Horse();
22
+    FarmVehicle cropDuster = new FarmVehicle("cropduster", "fertilize");
23
+    FarmVehicle tractor = new FarmVehicle("tractor", "harvest");
24
+
25
+    @Test
26
+    public void testMountHorse() {
27
+
28
+        String expected = "";
29
+        String actual = froilan.mount(horse);
30
+
31
+        Assert.assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void testDismountHorse() {
36
+
37
+        String expected = "";
38
+        String actual = freelan.dismount(horse);
39
+
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void testFeedHorse() {
45
+        Map<String, Integer> map = horse.eat("corn", 3);
46
+
47
+        Integer expectedTestCount = 3;
48
+        Assert.assertEquals(expectedTestCount, map.get("corn"));
49
+    }
50
+
51
+    @Test
52
+    public void testFroilanEat() {
53
+        Map<String, Integer> foodList = froilan.eat("egg", 5);
54
+
55
+        Integer expectedTestCount = 5;
56
+        Assert.assertEquals(expectedTestCount, foodList.get("egg"));
57
+    }
58
+
59
+    @Test
60
+    public void testFroilandaEat() {
61
+        Map<String, Integer> foodList = froilanda.eat("tomato", 3);
62
+
63
+        Integer expectedTestCount = 3;
64
+        Assert.assertEquals(expectedTestCount, foodList.get("tomato"));
65
+    }
66
+
67
+    @Test
68
+    public void testMakeNoise() {
69
+
70
+        String expected = "Hello!";
71
+        String actual = freelan.makeNoise(expected);
72
+
73
+        org.junit.Assert.assertEquals(expected, actual);
74
+    }
75
+
76
+    @Test
77
+    public void testFroilandaFertilize() {
78
+        FarmVehicle cropDuster = new FarmVehicle("cropDuster", "fertilize");
79
+        String expected = "Used cropDuster to fertilize corn and tomato";
80
+        String actual = froilanda.fertilize(" corn and tomato");
81
+
82
+        Assert.assertEquals(expected, actual);
83
+    }
84
+
85
+    @Test
86
+    public void testFroilanPlantCrop() {
87
+        HashMap expected = froilan.plant("corn", "row 1");
88
+
89
+        org.junit.Assert.assertEquals(expected, froilan.plant("corn", "row 1"));
90
+    }
91
+
92
+    @Test
93
+    public void testFreelanPlantCrop() {
94
+        HashMap expected = froilan.plant("tomato", "row 2");
95
+
96
+        org.junit.Assert.assertEquals(expected, froilan.plant("tomato", "row 2"));
97
+    }
98
+
99
+    @Test
100
+    public void testFroilanHarvest() {
101
+
102
+        HashMap actual = froilan.harvest(froilan.plant("corn", "row 1"));
103
+       Assert.assertEquals(froilan.plant("corn", "row 1"), actual);
104
+    }
105
+
106
+    @Test
107
+    public void testFroilanPlant() {
108
+        HashMap expected = froilan.plant("some crops", "last row");
109
+
110
+        org.junit.Assert.assertEquals(expected, froilan.plant("some crops", "last row"));
111
+    }
112
+
113
+    @Test
114
+    public void testChickenYield(){
115
+        Chicken chicken = new Chicken();
116
+        ArrayList<String> actual = chicken.yield(false, "egg");
117
+
118
+        Assert.assertEquals(chicken.yield(false, "egg"), actual);
119
+
120
+    }
121
+
122
+    @Test
123
+    public void testCropYield(){
124
+        Crop crop = new Crop();
125
+        ArrayList<String> actual = crop.yield(true, "tomato");
126
+
127
+        Assert.assertEquals(crop.yield(true, "tomato"), actual);
128
+
129
+    }
130
+
131
+    @Test
132
+    public void testChickenEat() {
133
+        Chicken chicken = new Chicken();
134
+        Map<String, Integer> map = chicken.eat("chicken food", 1);
135
+
136
+        Integer expectedTestCount = 1;
137
+        Assert.assertEquals(expectedTestCount, map.get("chicken food"));
138
+    }
139
+
140
+    @Test
141
+    public void testChickenMakeNoise(){
142
+        Chicken chicken = new Chicken();
143
+        String expected = "Hi, I'm a chicken";
144
+        String actual = chicken.makeNoise("Hi, I'm a chicken");
145
+        Assert.assertEquals(expected, actual);
146
+    }
147
+
148
+    @Test
149
+    public void setAndGetCropRow(){
150
+        Field field = new Field();
151
+
152
+        field.setCropRow("row 1");
153
+        String expected = "row 1";
154
+
155
+        String actual = field.getCropRow();
156
+        Assert.assertEquals(expected, actual);
157
+
158
+    }
159
+}