瀏覽代碼

finished FizzBuzz

Tommy Rogers 8 年之前
父節點
當前提交
48cf4595b3
共有 6 個檔案被更改,包括 86 行新增0 行删除
  1. 二進制
      FizzBuzz.class
  2. 9
    0
      FizzBuzz.ctxt
  3. 39
    0
      FizzBuzz.java
  4. 二進制
      FizzBuzzTest.class
  5. 6
    0
      FizzBuzzTest.ctxt
  6. 32
    0
      FizzBuzzTest.java

二進制
FizzBuzz.class 查看文件


+ 9
- 0
FizzBuzz.ctxt 查看文件

1
+#BlueJ class context
2
+comment0.target=FizzBuzz
3
+comment0.text=\n\ Write\ a\ description\ of\ class\ FizzBuzz\ here.\n\n\ @author\ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=number
5
+comment1.target=java.lang.String\ printLine(int)
6
+comment1.text=\n\ An\ example\ of\ a\ method\ -\ replace\ this\ comment\ with\ your\ own\n\n\ @param\ \ y\ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ the\ sum\ of\ x\ and\ y\n
7
+comment2.params=number
8
+comment2.target=java.lang.String\ printFizzBuzz(int)
9
+numComments=3

+ 39
- 0
FizzBuzz.java 查看文件

1
+
2
+/**
3
+ * Write a description of class FizzBuzz here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class FizzBuzz
9
+{
10
+    String start = "";
11
+    /**
12
+     * An example of a method - replace this comment with your own
13
+     *
14
+     * @param  y  a sample parameter for a method
15
+     * @return    the sum of x and y
16
+     */
17
+    public String printLine(int number)
18
+    {
19
+        for(int x = 1; x <= number; x++){
20
+        start += x + " ";
21
+        }
22
+        
23
+        return start;
24
+    }
25
+    
26
+    public String printFizzBuzz(int number){
27
+    for(int x = 1; x <= number; x++){    
28
+    if(x % 15 ==0)
29
+    start +="FizzBuzz ";
30
+    else if (x % 3 ==0)
31
+    start +="Fizz ";
32
+    else if (x % 5 ==0)
33
+    start +="Buzz ";
34
+    else 
35
+    start += x + " ";
36
+    }
37
+    return start;
38
+    }
39
+}

二進制
FizzBuzzTest.class 查看文件


+ 6
- 0
FizzBuzzTest.ctxt 查看文件

1
+#BlueJ class context
2
+comment0.target=FizzBuzzTest
3
+comment0.text=\n\ The\ test\ class\ FizzBuzz.\n\n\ @author\ \ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=
5
+comment1.target=void\ testThreeToFifty()
6
+numComments=2

+ 32
- 0
FizzBuzzTest.java 查看文件

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 FizzBuzz.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class FizzBuzzTest
15
+{
16
+    FizzBuzz fizzBuzz = new FizzBuzz();
17
+    
18
+    @Test
19
+    public void testThreeToFifty()
20
+    {
21
+        
22
+        
23
+        String expected = "1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz "
24
+        + "11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz "+
25
+        "26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 "
26
+        +"44 FizzBuzz 46 47 Fizz 49 Buzz ";
27
+        String actual = fizzBuzz.printFizzBuzz(50);
28
+        
29
+        assertEquals(expected, actual);
30
+        
31
+    }
32
+}