소스 검색

super human

Owen Murphy 6 년 전
부모
커밋
4dd21e267e

+ 41
- 0
src/main/java/Superpowers/Human.java 파일 보기

@@ -7,4 +7,45 @@ package Superpowers;
7 7
  * hero name, super ability. As before, create methods for retrieving field data and printing to screen.
8 8
  */
9 9
 public class Human {
10
+
11
+   private String name;
12
+   private int age;
13
+   private String gender;
14
+   private String occupation;
15
+   private String address;
16
+
17
+   public Human(){
18
+
19
+   }
20
+
21
+   public Human(String name, int age, String gender, String occupation, String address){
22
+       this.name = name;
23
+       this.age = age;
24
+       this.gender = gender;
25
+       this.occupation = occupation;
26
+       this.address = address;
27
+
28
+   }
29
+
30
+   public String getName(){
31
+       return name;
32
+   }
33
+
34
+    public int getAge() {
35
+        return age;
36
+    }
37
+
38
+    public String getGender(){
39
+       return gender;
40
+    }
41
+
42
+    public String getOccupation(){
43
+       return occupation;
44
+    }
45
+
46
+    public String getAddress(){
47
+       return address;
48
+    }
10 49
 }
50
+
51
+

+ 41
- 0
src/main/java/Superpowers/SuperHuman.java 파일 보기

@@ -0,0 +1,41 @@
1
+package Superpowers;
2
+
3
+public class SuperHuman extends Human {
4
+
5
+    private boolean good;
6
+    private boolean bad;
7
+    private String heroName;
8
+    private String superAbility;
9
+
10
+
11
+
12
+
13
+
14
+
15
+    public SuperHuman(String name, int age, String gender, String occupation, String address, String heroName, String superAbility, boolean good, boolean bad ) {
16
+
17
+        super(name, age, gender, occupation, address);
18
+        this.good = good;
19
+        this.bad = bad;
20
+        this.heroName = heroName;
21
+        this.superAbility = superAbility;
22
+
23
+
24
+    }
25
+
26
+    public boolean getGood() {
27
+        return good;
28
+    }
29
+
30
+    public boolean getBad(){
31
+        return bad;
32
+    }
33
+
34
+    public String getheroName(){
35
+        return heroName;
36
+    }
37
+    public String getsuperAbility(){
38
+        return superAbility;
39
+    }
40
+}
41
+

+ 16
- 0
src/test/java/Superpowers/HumanTest.java 파일 보기

@@ -1,5 +1,21 @@
1 1
 package Superpowers;
2 2
 
3 3
 
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
4 7
 public class HumanTest {
8
+    @Test
9
+    public void testFields(){
10
+        Human human = new Human("Bob", 36, "Male", "carpenter", "address");
11
+
12
+        Assert.assertEquals("Bob", human.getName());
13
+        Assert.assertEquals(36, human.getAge());
14
+        Assert.assertEquals("Male", human.getGender());
15
+        Assert.assertEquals("carpenter", human.getOccupation());
16
+        Assert.assertEquals("address", human.getAddress());
17
+
18
+    }
19
+
20
+
5 21
 }

+ 26
- 0
src/test/java/Superpowers/TestSuperHuman.java 파일 보기

@@ -0,0 +1,26 @@
1
+package Superpowers;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class TestSuperHuman {
7
+    @Test
8
+    public void SuperHumanTest(){
9
+        SuperHuman superHuman = new SuperHuman("Bob", 36, "Male", "carpenter",
10
+                "address", "superBeast", "Git What chu Need", true,  false );
11
+
12
+
13
+        Assert.assertEquals("superBeast", superHuman.getheroName());
14
+        Assert.assertEquals("Git What chu Need", superHuman.getsuperAbility());
15
+        Assert.assertEquals(true, superHuman.getGood());
16
+        Assert.assertEquals(false, superHuman.getBad());
17
+
18
+        Assert.assertEquals("Bob", superHuman.getName());
19
+        Assert.assertEquals(36, superHuman.getAge());
20
+        Assert.assertEquals("Male", superHuman.getGender());
21
+        Assert.assertEquals("carpenter", superHuman.getOccupation());
22
+        Assert.assertEquals("address", superHuman.getAddress());
23
+
24
+    }
25
+
26
+}