BlackJack 8 år sedan
förälder
incheckning
51ee96b85a
5 ändrade filer med 235 tillägg och 89 borttagningar
  1. 32
    32
      Scrabble.java
  2. 62
    0
      ScrabbleTest.java
  3. 2
    2
      Squares.java
  4. 50
    0
      TriangleTwoTest.java
  5. 89
    55
      package.bluej

+ 32
- 32
Scrabble.java Visa fil

@@ -2,39 +2,39 @@ import java.io.*;
2 2
 
3 3
 class Scrabble
4 4
 {
5
-// A class to give you the scrabble score of a word
5
+    // A class to give you the scrabble score of a word
6 6
 
7
- public static void main(String[] args) throws IOException
8
- {
9
-  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10
-  System.out.print("Enter a word: ");
11
-  String word=in.readLine();
12
-  System.out.println("Scrabble score is: "+score(word));
13
- }
7
+    public static void main(String[] args) throws IOException
8
+    {
9
+        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10
+        System.out.print("Enter a word: ");
11
+        String word=in.readLine();
12
+        System.out.println("Scrabble score is: "+score(word));
13
+    }
14 14
 
15
- public static int score(String word)
16
- {
17
-  String uword=word.toUpperCase();
18
-  int score=0;
19
-  for(int i=0;i<uword.length();i++)
20
-     switch(uword.charAt(i))
21
-       {
22
-        case 'Q': case 'Z':
23
-          score+=10; break;
24
-        case 'J': case 'X':
25
-          score+=8; break;
26
-        case 'K':
27
-          score+=5; break;
28
-        case 'F': case 'H': case 'V': case 'W': case 'Y':
29
-          score+=4; break;
30
-        case 'B': case 'C': case 'M': case 'P':
31
-          score+=3; break;
32
-        case 'D': case 'G':
33
-          score+=2;break;
34
-        default:
35
-          score+=1;break;
36
-      } 
37
-  return score;
38
- }
15
+    public static int score(String word)
16
+    {
17
+        String uword=word.toUpperCase();
18
+        int score=0;
19
+        for(int i=0;i<uword.length();i++)
20
+            switch(uword.charAt(i))
21
+            {
22
+                case 'Q': case 'Z':
23
+                score+=10; break;
24
+                case 'J': case 'X':
25
+                score+=8; break;
26
+                case 'K':
27
+                score+=5; break;
28
+                case 'F': case 'H': case 'V': case 'W': case 'Y':
29
+                score+=4; break;
30
+                case 'B': case 'C': case 'M': case 'P':
31
+                score+=3; break;
32
+                case 'D': case 'G':
33
+                score+=2;break;
34
+                default:
35
+                score+=1;break;
36
+            } 
37
+        return score;
38
+    }
39 39
 
40 40
 }

+ 62
- 0
ScrabbleTest.java Visa fil

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

+ 2
- 2
Squares.java Visa fil

@@ -4,10 +4,10 @@ class Squares
4 4
 
5 5
  static final int LIMIT=150;
6 6
 
7
- public void display(int limit)
7
+ public void display(int LIMIT)
8 8
  {
9 9
   int i;
10
-  for(i=1;i*i<limit;i++)
10
+  for(i=1;i*i<LIMIT;i++)
11 11
      {
12 12
       System.out.print("The square of "+i);
13 13
       System.out.println(" is "+i*i);

+ 50
- 0
TriangleTwoTest.java Visa fil

@@ -0,0 +1,50 @@
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 TriangleTwoTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class TriangleTwoTest
15
+{
16
+    /**
17
+     * Default constructor for test class TriangleTwoTest
18
+     */
19
+    public TriangleTwoTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+    @Test
44
+    public void test1()
45
+    {
46
+        TriangleTwo triangle2 = new TriangleTwo();
47
+        triangle2.display();
48
+    }
49
+}
50
+

+ 89
- 55
package.bluej Visa fil

@@ -1,26 +1,44 @@
1 1
 #BlueJ package file
2
-dependency1.from=Account
3
-dependency1.to=AccountException
2
+dependency1.from=Calendar1
3
+dependency1.to=CalendarGraphic
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=DepositAccount
6
-dependency2.to=AccountException
5
+dependency2.from=Calendar1
6
+dependency2.to=DateException
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
9
-editor.fx.0.width=800
10
-editor.fx.0.x=114
11
-editor.fx.0.y=175
8
+dependency3.from=Account
9
+dependency3.to=AccountException
10
+dependency3.type=UsesDependency
11
+dependency4.from=Calendar
12
+dependency4.to=DateException
13
+dependency4.type=UsesDependency
14
+dependency5.from=Date
15
+dependency5.to=DateException
16
+dependency5.type=UsesDependency
17
+dependency6.from=DepositAccount
18
+dependency6.to=AccountException
19
+dependency6.type=UsesDependency
20
+dependency7.from=ScrabbleTest
21
+dependency7.to=Scrabble
22
+dependency7.type=UsesDependency
23
+dependency8.from=TriangleTwoTest
24
+dependency8.to=TriangleTwo
25
+dependency8.type=UsesDependency
26
+editor.fx.0.height=667
27
+editor.fx.0.width=870
28
+editor.fx.0.x=267
29
+editor.fx.0.y=23
12 30
 objectbench.height=101
13
-objectbench.width=461
31
+objectbench.width=776
14 32
 package.divider.horizontal=0.6
15 33
 package.divider.vertical=0.8007380073800738
16 34
 package.editor.height=427
17 35
 package.editor.width=674
18
-package.editor.x=1006
19
-package.editor.y=133
36
+package.editor.x=134
37
+package.editor.y=31
20 38
 package.frame.height=600
21 39
 package.frame.width=800
22
-package.numDependencies=2
23
-package.numTargets=13
40
+package.numDependencies=8
41
+package.numTargets=15
24 42
 package.showExtends=true
25 43
 package.showUses=true
26 44
 project.charset=UTF-8
@@ -37,40 +55,56 @@ target1.width=130
37 55
 target1.x=450
38 56
 target1.y=190
39 57
 target10.height=50
40
-target10.name=Scrabble
58
+target10.name=ScrabbleTest
41 59
 target10.showInterface=false
42
-target10.type=ClassTarget
60
+target10.type=UnitTestTargetJunit4
43 61
 target10.width=80
44
-target10.x=10
45
-target10.y=250
62
+target10.x=40
63
+target10.y=220
64
+target11.association=ScrabbleTest
46 65
 target11.height=50
47
-target11.name=TriangleTwo
66
+target11.name=Scrabble
48 67
 target11.showInterface=false
49 68
 target11.type=ClassTarget
50
-target11.width=100
51
-target11.x=120
52
-target11.y=310
69
+target11.width=80
70
+target11.x=10
71
+target11.y=250
53 72
 target12.height=50
54
-target12.name=AccountException
73
+target12.name=DepositAccount
55 74
 target12.showInterface=false
56 75
 target12.type=ClassTarget
57
-target12.width=140
58
-target12.x=190
59
-target12.y=30
76
+target12.width=120
77
+target12.x=170
78
+target12.y=120
79
+target13.association=TriangleTwoTest
60 80
 target13.height=50
61
-target13.name=DateException
81
+target13.name=TriangleTwo
62 82
 target13.showInterface=false
63 83
 target13.type=ClassTarget
64
-target13.width=120
65
-target13.x=470
66
-target13.y=340
84
+target13.width=100
85
+target13.x=120
86
+target13.y=310
87
+target14.height=50
88
+target14.name=AccountException
89
+target14.showInterface=false
90
+target14.type=ClassTarget
91
+target14.width=140
92
+target14.x=190
93
+target14.y=30
94
+target15.height=50
95
+target15.name=DateException
96
+target15.showInterface=false
97
+target15.type=ClassTarget
98
+target15.width=120
99
+target15.x=470
100
+target15.y=340
67 101
 target2.height=50
68
-target2.name=Account
102
+target2.name=TriangleTwoTest
69 103
 target2.showInterface=false
70
-target2.type=ClassTarget
71
-target2.width=80
72
-target2.x=50
73
-target2.y=110
104
+target2.type=UnitTestTargetJunit4
105
+target2.width=100
106
+target2.x=150
107
+target2.y=280
74 108
 target3.height=50
75 109
 target3.name=Calendar1
76 110
 target3.showInterface=false
@@ -79,44 +113,44 @@ target3.width=90
79 113
 target3.x=330
80 114
 target3.y=220
81 115
 target4.height=50
82
-target4.name=Squares
116
+target4.name=Account
83 117
 target4.showInterface=false
84 118
 target4.type=ClassTarget
85 119
 target4.width=80
86
-target4.x=100
87
-target4.y=250
120
+target4.x=50
121
+target4.y=110
88 122
 target5.height=50
89
-target5.name=Calendar
123
+target5.name=Squares
90 124
 target5.showInterface=false
91 125
 target5.type=ClassTarget
92 126
 target5.width=80
93
-target5.x=490
94
-target5.y=270
127
+target5.x=100
128
+target5.y=250
95 129
 target6.height=50
96
-target6.name=TriangleOne
130
+target6.name=Calendar
97 131
 target6.showInterface=false
98 132
 target6.type=ClassTarget
99
-target6.width=100
100
-target6.x=10
101
-target6.y=310
133
+target6.width=80
134
+target6.x=490
135
+target6.y=270
102 136
 target7.height=50
103
-target7.name=TextIO
137
+target7.name=TriangleOne
104 138
 target7.showInterface=false
105 139
 target7.type=ClassTarget
106
-target7.width=80
107
-target7.x=490
108
-target7.y=40
140
+target7.width=100
141
+target7.x=10
142
+target7.y=310
109 143
 target8.height=50
110
-target8.name=Date
144
+target8.name=TextIO
111 145
 target8.showInterface=false
112 146
 target8.type=ClassTarget
113 147
 target8.width=80
114
-target8.x=350
115
-target8.y=290
148
+target8.x=490
149
+target8.y=40
116 150
 target9.height=50
117
-target9.name=DepositAccount
151
+target9.name=Date
118 152
 target9.showInterface=false
119 153
 target9.type=ClassTarget
120
-target9.width=120
121
-target9.x=170
122
-target9.y=120
154
+target9.width=80
155
+target9.x=350
156
+target9.y=290