#37 Khalil

Отворено
Ksaboor жели да споји 1 комит(е) из Ksaboor/CR-MicroLabs-Loops-NumbersTrianglesTables:master у master
4 измењених фајлова са 82 додато и 31 уклоњено
  1. 40
    6
      NumberUtilities.java
  2. 10
    3
      TableUtilities.java
  3. 14
    4
      TriangleUtilities.java
  4. 18
    18
      package.bluej

+ 40
- 6
NumberUtilities.java Прегледај датотеку

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

+ 10
- 3
TableUtilities.java Прегледај датотеку

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

+ 14
- 4
TriangleUtilities.java Прегледај датотеку

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

+ 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=800
12
+editor.fx.0.width=1280
13
+editor.fx.0.x=0
14
+editor.fx.0.y=0
15
+objectbench.height=156
16
+objectbench.width=352
17
+package.divider.horizontal=0.5780998389694042
18
+package.divider.vertical=0.7496159754224271
19
+package.editor.height=481
20
+package.editor.width=515
21
+package.editor.x=0
22
+package.editor.y=23
23
+package.frame.height=709
24
+package.frame.width=641
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true