Shivam Patel 6 лет назад
Родитель
Сommit
0b049bd9a4
10 измененных файлов: 430 добавлений и 9 удалений
  1. 20
    0
      Cat.java
  2. 53
    0
      CatTest.java
  3. 19
    0
      Dog.java
  4. 49
    0
      DogTest.java
  5. 39
    0
      MainApplication.java
  6. 43
    2
      MainApplicationTest.java
  7. 34
    0
      Pet.java
  8. 20
    0
      Rock.java
  9. 55
    0
      RockTest.java
  10. 98
    7
      package.bluej

+ 20
- 0
Cat.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+
2
+/**
3
+ * Write a description of class Cat here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Cat extends Pet
9
+{
10
+
11
+    public Cat(String name){
12
+        super(name);
13
+        super.setType("Cat");
14
+    }
15
+
16
+    public String speak(){
17
+
18
+        return "meowww";
19
+    }
20
+}

+ 53
- 0
CatTest.java Просмотреть файл

@@ -0,0 +1,53 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class CatTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class CatTest
15
+{
16
+    private Cat cat;
17
+    /**
18
+     * Default constructor for test class CatTest
19
+     */
20
+    public CatTest()
21
+    {
22
+    }
23
+
24
+    /**
25
+     * Sets up the test fixture.
26
+     *
27
+     * Called before every test case method.
28
+     */
29
+    @Before
30
+    public void setUp()
31
+    {
32
+        cat = new Cat("esteban");
33
+    }
34
+
35
+    /**
36
+     * Tears down the test fixture.
37
+     *
38
+     * Called after every test case method.
39
+     */
40
+    @After
41
+    public void tearDown()
42
+    {
43
+    }
44
+     @Test
45
+    public void testCat(){
46
+        String expected = "meowww";
47
+        
48
+        String actual = cat.speak();
49
+        
50
+        assertEquals(expected,actual);
51
+    
52
+    }
53
+}

+ 19
- 0
Dog.java Просмотреть файл

@@ -0,0 +1,19 @@
1
+
2
+/**
3
+ * Write a description of class Dog here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Dog extends Pet
9
+{
10
+    public Dog(String name){
11
+        super(name);
12
+        super.setType("Dog");
13
+    }
14
+
15
+    public String speak(){
16
+
17
+        return "woof";
18
+    }
19
+}

+ 49
- 0
DogTest.java Просмотреть файл

@@ -0,0 +1,49 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class DogTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class DogTest
15
+{
16
+    
17
+    private Pet dog;
18
+    
19
+  
20
+    /**
21
+     * Sets up the test fixture.
22
+     *
23
+     * Called before every test case method.
24
+     */
25
+    @Before
26
+    public void setUp()
27
+    {
28
+        dog = new Dog("leo");
29
+    }
30
+
31
+    /**
32
+     * Tears down the test fixture.
33
+     *
34
+     * Called after every test case method.
35
+     */
36
+    @After
37
+    public void tearDown()
38
+    {
39
+    }
40
+    
41
+    @Test
42
+    public void dogTest(){
43
+        String expected = "woof";
44
+        
45
+        String actual = dog.speak();
46
+        
47
+        assertEquals(expected, actual);
48
+    }
49
+}

+ 39
- 0
MainApplication.java Просмотреть файл

@@ -1,5 +1,44 @@
1 1
 /**
2 2
  * Created by leon on 11/6/17.
3 3
  */
4
+import java.util.*;
4 5
 public class MainApplication {
6
+    enum petTypes {CAT, DOG, ROCK};
7
+    public static void main(String[] args){
8
+
9
+        Scanner scan = new Scanner(System.in);
10
+        System.out.println("how many pets u have?");
11
+        int numPets = scan.nextInt();
12
+        scan.nextLine();
13
+        //String[] arr = new String[numPets];
14
+        Pet[] petArr = new Pet[numPets];
15
+
16
+        for(int i = 0; i<numPets; i++){
17
+            System.out.println("what type of pet?");
18
+            String typePet = scan.nextLine();
19
+            System.out.println("whats it's name?");           
20
+            String namePet = scan.nextLine();
21
+
22
+            switch(petTypes.valueOf(typePet.toUpperCase())){
23
+
24
+                case CAT:
25
+                petArr[i] = new Cat(namePet);
26
+                break;
27
+
28
+                case DOG:
29
+                petArr[i] = new Dog(namePet);
30
+                break;
31
+
32
+                case ROCK:
33
+                petArr[i] = new Rock(namePet);
34
+                break;
35
+            }
36
+
37
+        }
38
+        for(Pet i : petArr){
39
+            System.out.println("My pet " + i.getType() 
40
+                + ", " + i.getName() + " says " + i.speak());
41
+
42
+        }
43
+    }
5 44
 }

+ 43
- 2
MainApplicationTest.java Просмотреть файл

@@ -1,6 +1,47 @@
1 1
 
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
2 8
 /**
3
- * Created by leon on 11/6/17.
9
+ * The test class MainApplicationTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
4 13
  */
5
-public class MainApplicationTest {
14
+public class MainApplicationTest
15
+{
16
+    
17
+    
18
+    /**
19
+     * Default constructor for test class MainApplicationTest
20
+     */
21
+    public MainApplicationTest()
22
+    {
23
+    }
24
+
25
+    /**
26
+     * Sets up the test fixture.
27
+     *
28
+     * Called before every test case method.
29
+     */
30
+    @Before
31
+    public void setUp()
32
+    {
33
+        
34
+    }
35
+
36
+    /**
37
+     * Tears down the test fixture.
38
+     *
39
+     * Called after every test case method.
40
+     */
41
+    @After
42
+    public void tearDown()
43
+    {
44
+    }
45
+    
46
+    
6 47
 }

+ 34
- 0
Pet.java Просмотреть файл

@@ -0,0 +1,34 @@
1
+
2
+/**
3
+ * Write a description of class Pet here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Pet
9
+{
10
+    private String name;
11
+    private String type;
12
+
13
+    public Pet(String name){
14
+        this.name = name;
15
+
16
+    }
17
+
18
+    public void setType(String type) {
19
+        this.type = type;
20
+    }
21
+
22
+    public String getType(){
23
+        return type;
24
+    }
25
+
26
+    public String getName(){
27
+        return name;
28
+    }
29
+
30
+    public String speak(){
31
+
32
+        return "something";
33
+    }
34
+}

+ 20
- 0
Rock.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+
2
+/**
3
+ * Write a description of class Rock here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Rock extends Pet
9
+{
10
+    public Rock(String name){
11
+
12
+        super(name);
13
+        super.setType("Rock");
14
+    }
15
+
16
+    public String speak(){
17
+
18
+        return "wtf";
19
+    }
20
+}

+ 55
- 0
RockTest.java Просмотреть файл

@@ -0,0 +1,55 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class RockTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class RockTest
15
+{
16
+    private Rock rock;
17
+    
18
+    /**
19
+     * Default constructor for test class RockTest
20
+     */
21
+    public RockTest()
22
+    {
23
+    }
24
+
25
+    /**
26
+     * Sets up the test fixture.
27
+     *
28
+     * Called before every test case method.
29
+     */
30
+    @Before
31
+    public void setUp()
32
+    {
33
+        rock = new Rock("rocky");
34
+    }
35
+
36
+    /**
37
+     * Tears down the test fixture.
38
+     *
39
+     * Called after every test case method.
40
+     */
41
+    @After
42
+    public void tearDown()
43
+    {
44
+    }
45
+    
46
+    @Test
47
+    public void testRock(){
48
+        String expected = "wtf";
49
+        
50
+        String actual = rock.speak();
51
+        
52
+        assertEquals(expected,actual);
53
+    
54
+    }
55
+}

+ 98
- 7
package.bluej Просмотреть файл

@@ -1,10 +1,34 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=560
5
-editor.fx.0.y=117
2
+dependency1.from=MainApplication
3
+dependency1.to=Pet
4
+dependency1.type=UsesDependency
5
+dependency2.from=MainApplication
6
+dependency2.to=Cat
7
+dependency2.type=UsesDependency
8
+dependency3.from=MainApplication
9
+dependency3.to=Dog
10
+dependency3.type=UsesDependency
11
+dependency4.from=MainApplication
12
+dependency4.to=Rock
13
+dependency4.type=UsesDependency
14
+dependency5.from=DogTest
15
+dependency5.to=Pet
16
+dependency5.type=UsesDependency
17
+dependency6.from=DogTest
18
+dependency6.to=Dog
19
+dependency6.type=UsesDependency
20
+dependency7.from=RockTest
21
+dependency7.to=Rock
22
+dependency7.type=UsesDependency
23
+dependency8.from=CatTest
24
+dependency8.to=Cat
25
+dependency8.type=UsesDependency
26
+editor.fx.0.height=22
27
+editor.fx.0.width=0
28
+editor.fx.0.x=40
29
+editor.fx.0.y=970
6 30
 objectbench.height=101
7
-objectbench.width=461
31
+objectbench.width=776
8 32
 package.divider.horizontal=0.6
9 33
 package.divider.vertical=0.8007380073800738
10 34
 package.editor.height=427
@@ -13,8 +37,8 @@ package.editor.x=141
13 37
 package.editor.y=59
14 38
 package.frame.height=600
15 39
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=0
40
+package.numDependencies=8
41
+package.numTargets=9
18 42
 package.showExtends=true
19 43
 package.showUses=true
20 44
 project.charset=UTF-8
@@ -23,3 +47,70 @@ readme.name=@README
23 47
 readme.width=47
24 48
 readme.x=10
25 49
 readme.y=10
50
+target1.association=RockTest
51
+target1.height=50
52
+target1.name=Rock
53
+target1.showInterface=false
54
+target1.type=ClassTarget
55
+target1.width=80
56
+target1.x=270
57
+target1.y=340
58
+target2.height=50
59
+target2.name=MainApplicationTest
60
+target2.showInterface=false
61
+target2.type=UnitTestTargetJunit4
62
+target2.width=120
63
+target2.x=60
64
+target2.y=70
65
+target3.association=CatTest
66
+target3.height=50
67
+target3.name=Cat
68
+target3.showInterface=false
69
+target3.type=ClassTarget
70
+target3.width=80
71
+target3.x=530
72
+target3.y=180
73
+target4.height=50
74
+target4.name=RockTest
75
+target4.showInterface=false
76
+target4.type=UnitTestTargetJunit4
77
+target4.width=80
78
+target4.x=300
79
+target4.y=310
80
+target5.height=50
81
+target5.name=CatTest
82
+target5.showInterface=false
83
+target5.type=UnitTestTargetJunit4
84
+target5.width=80
85
+target5.x=560
86
+target5.y=150
87
+target6.height=50
88
+target6.name=DogTest
89
+target6.showInterface=false
90
+target6.type=UnitTestTargetJunit4
91
+target6.width=80
92
+target6.x=180
93
+target6.y=250
94
+target7.association=DogTest
95
+target7.height=50
96
+target7.name=Dog
97
+target7.showInterface=false
98
+target7.type=ClassTarget
99
+target7.width=80
100
+target7.x=150
101
+target7.y=280
102
+target8.height=50
103
+target8.name=Pet
104
+target8.showInterface=false
105
+target8.type=ClassTarget
106
+target8.width=80
107
+target8.x=340
108
+target8.y=120
109
+target9.association=MainApplicationTest
110
+target9.height=50
111
+target9.name=MainApplication
112
+target9.showInterface=false
113
+target9.type=ClassTarget
114
+target9.width=120
115
+target9.x=30
116
+target9.y=100