소스 검색

Committing NumberTrianglesTablesi:

Navya Sanal 6 년 전
부모
커밋
edb4ee2bf2
5개의 변경된 파일129개의 추가작업 그리고 29개의 파일을 삭제
  1. 48
    13
      NumberUtilities.java
  2. 44
    4
      TableUtilities.java
  3. 32
    8
      TriangleUtilities.java
  4. 1
    0
      TriangleUtilitiesTest.java
  5. 4
    4
      package.bluej

+ 48
- 13
NumberUtilities.java 파일 보기

@@ -1,32 +1,67 @@
1
- 
2 1
 
3 2
 
4 3
 public class NumberUtilities {
5
-    
6
-    public static String getRange(int start) {
7
-        return null;
4
+
5
+    public static String getRange(int stop) {
6
+        StringBuilder builder = new StringBuilder();
7
+        for(int i= 0; i < stop ;i++)
8
+        {
9
+            builder.append(i);
10
+
11
+        }
12
+        return builder.toString();
8 13
     }
9
-    
14
+
10 15
     public static String getRange(int start, int stop) {
11
-        return null;
16
+        StringBuilder builder = new StringBuilder();
17
+        for(int i = start;i < stop;i++)
18
+        {
19
+            builder.append(i);
20
+        }
21
+        return builder.toString();
12 22
     }
13 23
 
14
-
15 24
     public static String getRange(int start, int stop, int step) {
16
-        return null;
25
+        StringBuilder builder = new StringBuilder();
26
+        for(int i =start; i < stop ;i = i + step)
27
+        {
28
+            builder.append(i);
29
+        }
30
+        return builder.toString();
17 31
     }
18
-    
19 32
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
33
+        StringBuilder builder = new StringBuilder();
34
+        for(int i =start; i < stop ;i++)
35
+        {
36
+            if(i % 2 == 0)
37
+            {
38
+                builder.append(i);
39
+            }
40
+        }
41
+        return builder.toString();
42
+        
21 43
     }
22 44
 
23 45
 
24 46
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
47
+       StringBuilder builder = new StringBuilder();
48
+        for(int i =start; i < stop ;i++)
49
+        {
50
+            if(i % 2 != 0)
51
+            {
52
+                builder.append(i);
53
+            }
54
+        }
55
+        return builder.toString();
26 56
     }
27 57
 
28
-
29 58
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
59
+        StringBuilder builder = new StringBuilder();
60
+        for(int i =start;i <= stop;i++)
61
+        {
62
+            int newPower = (int)Math.pow(i,exponent);
63
+            builder.append(newPower);
64
+        }
65
+          return builder.toString();  
31 66
     }
32 67
 }

+ 44
- 4
TableUtilities.java 파일 보기

@@ -1,15 +1,55 @@
1
- 
2 1
 
2
+import java.util.*;
3 3
 public class TableUtilities {
4
+
4 5
     public static String getSmallMultiplicationTable() {
5
-        return null;
6
+        StringBuilder build = new StringBuilder();
7
+
8
+        for(int i = 1;i <= 5;i++)
9
+        {
10
+            for(int j =1;j <= 5;j++)
11
+            {
12
+                int k  = i * j;
13
+                build.append(String.format("%3d |",k));
14
+
15
+            }
16
+            build.append("\n");
17
+        }
18
+        return build.toString();
6 19
     }
7 20
 
8 21
     public static String getLargeMultiplicationTable() {
9
-        return null;
22
+        StringBuilder build = new StringBuilder();
23
+
24
+        for(int i = 1;i <= 10;i++)
25
+        {
26
+            for(int j =1;j <= 10;j++)
27
+            {
28
+                int k  = i * j;
29
+                String x = String.format("%3d |",k);
30
+                build.append(x);
31
+
32
+            }
33
+            build.append("\n");
34
+        }
35
+        return build.toString();
10 36
     }
11 37
 
12 38
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
39
+        StringBuilder build = new StringBuilder();
40
+
41
+        for(int i = 1;i <= tableSize;i++)
42
+        {
43
+            for(int j =1;j <= tableSize;j++)
44
+            {
45
+                int k  = i * j;
46
+                String x = String.format("%3d |",k);
47
+                build.append(x);
48
+
49
+            }
50
+            build.append("\n");
51
+        }
52
+        return build.toString();
53
+
14 54
     }
15 55
 }

+ 32
- 8
TriangleUtilities.java 파일 보기

@@ -1,21 +1,45 @@
1
- 
2 1
 
3 2
 public class TriangleUtilities {
4
-
5
-    public static String getRow(int numberOfStars) {
6
-        return null;
3
+    public static String getRow(int numberOfRows) {
4
+        StringBuilder built = new StringBuilder();
5
+        for(int i = 0; i <numberOfRows;i++)
6
+        {
7
+            built.append("*");
8
+        }
9
+        return built.toString();
7 10
     }
8
-    
11
+
9 12
     public static String getTriangle(int numberOfRows) {
10
-        return null;
13
+        StringBuilder builder = new StringBuilder();
14
+        for(int i =0;i < numberOfRows;i++)
15
+        {
16
+            String k = getRow(i+1);
17
+            builder.append(k + "\n");
18
+        }
19
+        return builder.toString();
20
+
11 21
     }
12 22
 
23
+    
13 24
 
14 25
     public static String getSmallTriangle() {
15
-        return null;
26
+        StringBuilder built = new StringBuilder();
27
+        for(int i = 1;i <= 4;i++)
28
+        {
29
+            String k = getRow(i);
30
+            built.append(k + "\n");
31
+        }
32
+        return built.toString();
33
+
16 34
     }
17 35
 
18 36
     public static String getLargeTriangle() {
19
-        return null;
37
+        StringBuilder built = new StringBuilder();
38
+        for(int i = 1;i <= 9;i++)
39
+        {
40
+            String k = getRow(i);
41
+            built.append(k + "\n");
42
+        }
43
+        return built.toString();
20 44
     }
21 45
 }

+ 1
- 0
TriangleUtilitiesTest.java 파일 보기

@@ -56,6 +56,7 @@ public class TriangleUtilitiesTest {
56 56
         String actual = TriangleUtilities.getTriangle(3);
57 57
         
58 58
         // Then
59
+        System.out.println(actual);
59 60
         Assert.assertEquals(expected, actual);
60 61
     }
61 62
     

+ 4
- 4
package.bluej 파일 보기

@@ -10,11 +10,11 @@ dependency3.to=TableUtilities
10 10
 dependency3.type=UsesDependency
11 11
 editor.fx.0.height=722
12 12
 editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
13
+editor.fx.0.x=338
14
+editor.fx.0.y=23
15 15
 objectbench.height=164
16
-objectbench.width=484
17
-package.divider.horizontal=0.6
16
+objectbench.width=286
17
+package.divider.horizontal=0.6004098360655737
18 18
 package.divider.vertical=0.7560627674750356
19 19
 package.editor.height=523
20 20
 package.editor.width=382