Przeglądaj źródła

Updated NumbersTriangelsTables

Chaitali Patel 6 lat temu
rodzic
commit
98cad1df80
5 zmienionych plików z 112 dodań i 36 usunięć
  1. 37
    15
      NumberUtilities.java
  2. 33
    3
      TableUtilities.java
  3. 34
    8
      TriangleUtilities.java
  4. 0
    2
      TriangleUtilitiesTest.java
  5. 8
    8
      package.bluej

+ 37
- 15
NumberUtilities.java Wyświetl plik

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

+ 33
- 3
TableUtilities.java Wyświetl plik

@@ -2,14 +2,44 @@
2 2
 
3 3
 public class TableUtilities {
4 4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+       String str="";
6
+       
7
+        for(int i=1; i<=5; i++) {
8
+            int number=0;
9
+            for(int j=1; j<=5;j++){
10
+               number = i * j;
11
+               str += String.format("%3d |",number);
12
+        }
13
+         str +="\n";
14
+    }
15
+    return str;
6 16
     }
7 17
 
8 18
     public static String getLargeMultiplicationTable() {
9
-        return null;
19
+          String str="";
20
+       
21
+        for(int i=1; i<=10; i++) {
22
+            int number=0;
23
+            for(int j=1; j<=10;j++){
24
+               number = i * j;
25
+               str += String.format("%3d |",number);
26
+        }
27
+         str +="\n";
28
+    }
29
+    return str;
10 30
     }
11 31
 
12 32
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
33
+           String str="";
34
+       
35
+        for(int i=1; i<=tableSize; i++) {
36
+            int number=0;
37
+            for(int j=1; j<=tableSize;j++){
38
+               number = i * j;
39
+               str += String.format("%3d |",number);
40
+        }
41
+         str +="\n";
42
+    }
43
+    return str;
14 44
     }
15 45
 }

+ 34
- 8
TriangleUtilities.java Wyświetl plik

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

+ 0
- 2
TriangleUtilitiesTest.java Wyświetl plik

@@ -1,5 +1,3 @@
1
- 
2
-
3 1
 
4 2
 import org.junit.Assert;
5 3
 import org.junit.Test;

+ 8
- 8
package.bluej Wyświetl plik

@@ -10,17 +10,17 @@ 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
15
-objectbench.height=164
13
+editor.fx.0.x=478
14
+editor.fx.0.y=25
15
+objectbench.height=136
16 16
 objectbench.width=484
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
18
+package.divider.vertical=0.7559726962457338
19
+package.editor.height=436
20 20
 package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
21
+package.editor.x=772
22
+package.editor.y=103
23
+package.frame.height=644
24 24
 package.frame.width=508
25 25
 package.numDependencies=3
26 26
 package.numTargets=6