Selaa lähdekoodia

Added readme and comments on assignment

Nhu Nguyen 6 vuotta sitten
vanhempi
commit
82e34c6617
6 muutettua tiedostoa jossa 223 lisäystä ja 82 poistoa
  1. 37
    19
      Bonus.java
  2. 47
    16
      MathUtilities.java
  3. 52
    16
      MathUtilitiesTest.java
  4. 32
    0
      README.MD
  5. 0
    12
      README.TXT
  6. 55
    19
      package.bluej

+ 37
- 19
Bonus.java Näytä tiedosto

@@ -1,22 +1,40 @@
1
-
2
-/**
3
- * Write a description of class Bonus here.
4
- *
5
- * @author (your name)
6
- * @version (a version number or a date)
7
- */
8 1
 public class Bonus
9 2
 {
10
-    public String acronym(String phrase) {
11
-        return null;
12
-    }
13
-    
14
-    public String encrypt(String word) {
15
-        return null;
16
-    }
17
-   
18
-    
19
-    public int factorial(int number){
20
-        return -1;
21
-    }
3
+
4
+      /**
5
+       * Given a number, return the factorial of that number.
6
+       * For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
7
+       * @param number
8
+       * @return the factorial of the number
9
+       */
10
+      public int factorial(int number){
11
+          return -1;
12
+      }
13
+
14
+      /**
15
+       * Given a phrase, get the acronym of that phrase. Acronym is the combination of
16
+       * the first character of each word in upper case.
17
+       * For example, given "Ruby on Rails", this method will return "ROR"
18
+       * @param phrase
19
+       * @return Upper case of the first letter of each word
20
+       */
21
+      public String acronym(String phrase) {
22
+          return null;
23
+      }
24
+
25
+      /**
26
+       * To prevent anyone from reading our messages, we can encrypt it so it will not be readable by anyone except it
27
+       * intended audience. This method encrypt the message by shifting the character by 3 characters. If the character is
28
+       * at the end of the alphabet, it will wraps around.
29
+       * For example:
30
+       *  'a' => 'd'
31
+       *  'w' => 'z'
32
+       *  'x' => 'a'
33
+       *  'y' => 'b'
34
+       * @param word
35
+       * @return the encrypted string by shifting each character by three character
36
+       */
37
+      public String encrypt(String word) {
38
+          return null;
39
+      }
22 40
 }

+ 47
- 16
MathUtilities.java Näytä tiedosto

@@ -1,19 +1,50 @@
1 1
 public class MathUtilities{
2
-    
3
-    public int add(int num1, int num2){
4
-        return -1;
5
-    }
6
-    
7
-    public double add(double num1, double num2){
8
-        return -1;
9
-    }
10
-    
11
-    public double half(int number) {
12
-        return -1;
13
-    }
14
-    
15
-    public boolean isOdd(int number){
16
-        return false;
17
-    }
2
+  /**
3
+   * Add two number together
4
+   * @param num1 first number
5
+   * @param num2 second number
6
+   * @return the sum of the two numbers
7
+   */
8
+  public int add(int num1, int num2){
9
+      return -1;
10
+  }
11
+
12
+  /**
13
+   * Add two number together
14
+   * @param num1 first number
15
+   * @param num2 second number
16
+   * @return the sum of the two numbers
17
+   */
18
+  public double add(double num1, double num2){
19
+      return -1;
20
+  }
21
+
22
+  /**
23
+   * Get half the value of the number
24
+   * @param number the number given
25
+   * @return the half of the number in double
26
+   */
27
+  public double half(int number) {
28
+      return -1;
29
+  }
30
+
31
+  /**
32
+   * Determine if the number is odd
33
+   * @param number the number given
34
+   * @return true if the number is odd, false if it is even
35
+   */
36
+  public boolean isOdd(int number){
37
+      return false;
38
+  }
39
+
40
+
41
+  /**
42
+   * Multiply the number by itself
43
+   * @param number the number given
44
+   * @return the result of the number multiply by itself
45
+   */
46
+  public int square(int number) {
47
+      return -1;
48
+  }
18 49
 
19 50
 }

+ 52
- 16
MathUtilitiesTest.java Näytä tiedosto

@@ -14,62 +14,98 @@ public class MathUtilitiesTest
14 14
     public void setup(){
15 15
         utilities = new MathUtilities();
16 16
     }
17
-    
17
+
18 18
     @Test
19 19
     public void testAddInteger(){
20 20
         //Given
21 21
         int expected = 15;
22
-        
22
+
23 23
         //When
24 24
         int actual = utilities.add(7, 8);
25
-        
25
+
26 26
         //Then
27 27
         assertEquals(expected, actual);
28 28
     }
29
-    
29
+
30 30
     @Test
31 31
     public void testAddDouble(){
32 32
         //Given
33 33
         double expected = 11.22;
34
-        
34
+
35 35
         //When
36 36
         double actual = utilities.add(10, 1.22);
37
-        
37
+
38 38
         //Then
39 39
         assertEquals(expected, actual, DELTA);
40 40
     }
41
-    
41
+
42 42
     @Test
43 43
     public void testHalfForEven(){
44 44
         //Given
45 45
         double expected = 2.0;
46
-        
46
+
47 47
         //When
48 48
         double actual = utilities.half(4);
49
-        
49
+
50 50
         //Then
51 51
         assertEquals(expected, actual, DELTA);
52 52
     }
53
-    
53
+
54 54
     @Test
55 55
     public void testHalfForOdd(){
56 56
         //Given
57 57
         double expected = 12.5;
58
-        
58
+
59 59
         //When
60 60
         double actual = utilities.half(25);
61
-        
61
+
62 62
         //Then
63 63
         assertEquals(expected, actual, DELTA);
64 64
     }
65
-    
65
+
66 66
     @Test
67
-    public void testIsOdd_forOddNumber(){
67
+    public void testIsOddForOddNumber(){
68 68
         assertTrue(utilities.isOdd(7));
69 69
     }
70
-    
70
+
71 71
     @Test
72
-    public void testIsOdd_forEvenNumber(){
72
+    public void testIsOddForEvenNumber(){
73 73
         assertFalse(utilities.isOdd(12));
74 74
     }
75
+
76
+    @Test
77
+    public void testSquareForBaseCase() {
78
+      //Given
79
+      int expected = 1;
80
+
81
+      //When
82
+      int actual = utilities.square(1);
83
+
84
+      //Then
85
+      assertEquals(expected, actual);
86
+    }
87
+
88
+    @Test
89
+    public void testSquareForOneDigit() {
90
+      //Given
91
+      int expected = 9;
92
+
93
+      //When
94
+      int actual = utilities.square(3);
95
+
96
+      //Then
97
+      assertEquals(expected, actual);
98
+    }
99
+
100
+    @Test
101
+    public void testSquareForTwoDigit() {
102
+      //Given
103
+      int expected = 121;
104
+
105
+      //When
106
+      int actual = utilities.square(11);
107
+
108
+      //Then
109
+      assertEquals(expected, actual);
110
+    }
75 111
 }

+ 32
- 0
README.MD Näytä tiedosto

@@ -0,0 +1,32 @@
1
+# Quiz 1
2
+You have one hour to complete this quiz. You are required to do section 1 & 2. Section 3 is a bonus section, which means do it if you finish the other two sections before the hour is up.
3
+
4
+### **Instructions:**
5
+
6
+1. Fork this Repository
7
+    * [fork](https://help.github.com/articles/fork-a-repo/) this repository to your personal github account
8
+    * [clone](https://help.github.com/articles/cloning-a-repository/) **your** `forked` repository to your local machine
9
+    * Write the code to make all the tests pass. See below for instructions.
10
+      * MAKE SURE YOUR CODE COMPILES
11
+      * Run the test to verify your code
12
+    * `git add .` to add files you want to commit
13
+    * `git commit -m "commit message"` to commit your changes
14
+    * `git push` your staged files to your remote repository
15
+    * submit a `pull request` which compares Zipcoder `master` to your `master`
16
+
17
+## Section 1 - MathUtilities
18
+Make all the tests in the `MathUtilitiesTest` class pass. All the methods have been stubbed out for you in the `MathUtilities` class. Each of the method has a comment above it to describe the expected behavior. Look at the test case to see example of input and expected output.
19
+  - `int add(int num1, int num2)`
20
+  - `double add(double num1, double num2)`
21
+  - `double half(int number)`
22
+  - `boolean isOdd(int number)`
23
+  - `int square(int number)`
24
+
25
+## Section 2 - StringUtilities
26
+Make all the tests in the `StringUtilitiesTest` class pass. All the methods have been stubbed out for you in the `StringUtilities` class. Each of the method has a comment above it to describe the expected behavior. Look at the test case to see example of input and expected output.
27
+
28
+  - `Character getMiddleCharacter(String word)`
29
+  - `String removeCharacter(String value, char charToRemove)`
30
+  - `String getLastWord(String value)`
31
+
32
+## Section 3 - Bonus

+ 0
- 12
README.TXT Näytä tiedosto

@@ -1,12 +0,0 @@
1
-------------------------------------------------------------------------
2
-This is the project README file. Here, you should describe your project.
3
-Tell the reader (someone who does not know anything about this project)
4
-all he/she needs to know. The comments should usually include at least:
5
-------------------------------------------------------------------------
6
-
7
-PROJECT TITLE:
8
-PURPOSE OF PROJECT:
9
-VERSION or DATE:
10
-HOW TO START THIS PROJECT:
11
-AUTHORS:
12
-USER INSTRUCTIONS:

+ 55
- 19
package.bluej Näytä tiedosto

@@ -2,22 +2,28 @@
2 2
 dependency1.from=StringUtilitiesTest
3 3
 dependency1.to=StringUtilities
4 4
 dependency1.type=UsesDependency
5
+dependency2.from=BonusTest
6
+dependency2.to=Bonus
7
+dependency2.type=UsesDependency
8
+dependency3.from=MathUtilitiesTest
9
+dependency3.to=MathUtilities
10
+dependency3.type=UsesDependency
5 11
 editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=166
8
-editor.fx.0.y=127
12
+editor.fx.0.width=876
13
+editor.fx.0.x=158
14
+editor.fx.0.y=216
9 15
 objectbench.height=164
10
-objectbench.width=776
16
+objectbench.width=669
11 17
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6845018450184502
13
-package.editor.height=364
14
-package.editor.width=674
18
+package.divider.vertical=0.7628294036061026
19
+package.editor.height=543
20
+package.editor.width=567
15 21
 package.editor.x=557
16 22
 package.editor.y=43
17
-package.frame.height=600
18
-package.frame.width=800
19
-package.numDependencies=1
20
-package.numTargets=2
23
+package.frame.height=779
24
+package.frame.width=693
25
+package.numDependencies=3
26
+package.numTargets=6
21 27
 package.showExtends=true
22 28
 package.showUses=true
23 29
 project.charset=UTF-8
@@ -31,13 +37,43 @@ target1.name=StringUtilitiesTest
31 37
 target1.showInterface=false
32 38
 target1.type=UnitTestTargetJunit4
33 39
 target1.width=110
34
-target1.x=100
35
-target1.y=-20
36
-target2.association=StringUtilitiesTest
40
+target1.x=110
41
+target1.y=150
37 42
 target2.height=50
38
-target2.name=StringUtilities
43
+target2.name=BonusTest
39 44
 target2.showInterface=false
40
-target2.type=ClassTarget
41
-target2.width=110
42
-target2.x=70
43
-target2.y=10
45
+target2.type=UnitTestTargetJunit4
46
+target2.width=80
47
+target2.x=120
48
+target2.y=270
49
+target3.association=BonusTest
50
+target3.height=50
51
+target3.name=Bonus
52
+target3.showInterface=false
53
+target3.type=ClassTarget
54
+target3.width=80
55
+target3.x=90
56
+target3.y=300
57
+target4.association=MathUtilitiesTest
58
+target4.height=50
59
+target4.name=MathUtilities
60
+target4.showInterface=false
61
+target4.type=ClassTarget
62
+target4.width=100
63
+target4.x=80
64
+target4.y=70
65
+target5.association=StringUtilitiesTest
66
+target5.height=50
67
+target5.name=StringUtilities
68
+target5.showInterface=false
69
+target5.type=ClassTarget
70
+target5.width=110
71
+target5.x=80
72
+target5.y=180
73
+target6.height=50
74
+target6.name=MathUtilitiesTest
75
+target6.showInterface=false
76
+target6.type=UnitTestTargetJunit4
77
+target6.width=100
78
+target6.x=110
79
+target6.y=40