#36 dmjpub

Открыто
dmjpub хочет смерджить 3 коммит(ов) из dmjpub/CR-MicroLabs-Loops-NumbersTrianglesTables:master в master
5 измененных файлов: 88 добавлений и 39 удалений
  1. 38
    7
      NumberUtilities.java
  2. 0
    0
      README.TXT
  3. 16
    5
      TableUtilities.java
  4. 16
    9
      TriangleUtilities.java
  5. 18
    18
      package.bluej

+ 38
- 7
NumberUtilities.java Просмотреть файл

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

+ 0
- 0
README.TXT Просмотреть файл


+ 16
- 5
TableUtilities.java Просмотреть файл

@@ -1,15 +1,26 @@
1
- 
2 1
 
3 2
 public class TableUtilities {
3
+    
4
+    
4 5
     public static String getSmallMultiplicationTable() {
5
-        return null;
6
+        
7
+        return getMultiplicationTable(5);
6 8
     }
7 9
 
8
-    public static String getLargeMultiplicationTable() {
9
-        return null;
10
+    public static String getLargeMultiplicationTable() { 
11
+        return getMultiplicationTable(10);
10 12
     }
11 13
 
12 14
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
15
+        
16
+        StringBuilder sb = new StringBuilder();
17
+        //int tableSize = 5;
18
+        for(int i = 1; i <= tableSize; i++) {
19
+            for(int j = 1; j <= tableSize; j++) {
20
+                sb.append(String.format("%3d |", i * j));
21
+            }sb.append("\n");
22
+        }
23
+        return sb.toString();
14 24
     }
15 25
 }
26
+

+ 16
- 9
TriangleUtilities.java Просмотреть файл

@@ -1,21 +1,28 @@
1
- 
2 1
 
3 2
 public class TriangleUtilities {
4
-
5 3
     public static String getRow(int numberOfStars) {
6
-        return null;
4
+        String star = "*";
5
+        String output = "";
6
+        int n = numberOfStars;
7
+        for(int i =1; i<=n; i++) {
8
+            output += String.format("%s", star);
9
+        }
10
+        return output;
7 11
     }
8
-    
12
+
9 13
     public static String getTriangle(int numberOfRows) {
10
-        return null;
14
+        StringBuilder sb = new StringBuilder();
15
+        for(int i =1; i<=numberOfRows; i++) {
16
+            sb.append(getRow(i) + "\n");
17
+        }
18
+        return sb.toString();
11 19
     }
12 20
 
13
-
14 21
     public static String getSmallTriangle() {
15
-        return null;
22
+        return getTriangle(4);
16 23
     }
17
-
24
+    
18 25
     public static String getLargeTriangle() {
19
-        return null;
26
+        return getTriangle(9);
20 27
     }
21 28
 }

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

@@ -1,27 +1,27 @@
1 1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TableUtilitiesTest
3
+dependency1.to=TableUtilities
4 4
 dependency1.type=UsesDependency
5 5
 dependency2.from=TriangleUtilitiesTest
6 6
 dependency2.to=TriangleUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=NumberUtilitiesTest
9
+dependency3.to=NumberUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
12
-editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
15
-objectbench.height=164
16
-objectbench.width=484
17
-package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
20
-package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
24
-package.frame.width=508
11
+editor.fx.0.height=0
12
+editor.fx.0.width=0
13
+editor.fx.0.x=0
14
+editor.fx.0.y=0
15
+objectbench.height=152
16
+objectbench.width=424
17
+package.divider.horizontal=0.6002785515320335
18
+package.divider.vertical=0.7557603686635944
19
+package.editor.height=485
20
+package.editor.width=612
21
+package.editor.x=427
22
+package.editor.y=23
23
+package.frame.height=709
24
+package.frame.width=738
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true