Explorar el Código

NumbersTriangleTable

Soujanya Buragapu hace 6 años
padre
commit
488a6c7094
Se han modificado 4 ficheros con 139 adiciones y 42 borrados
  1. 36
    13
      NumberUtilities.java
  2. 45
    4
      TableUtilities.java
  3. 41
    8
      TriangleUtilities.java
  4. 17
    17
      package.bluej

+ 36
- 13
NumberUtilities.java Ver fichero

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

+ 45
- 4
TableUtilities.java Ver fichero

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

+ 41
- 8
TriangleUtilities.java Ver fichero

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

+ 17
- 17
package.bluej Ver fichero

@@ -1,26 +1,26 @@
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
11
+editor.fx.0.height=717
12
+editor.fx.0.width=988
13
+editor.fx.0.x=130
14
+editor.fx.0.y=23
15
+objectbench.height=153
16
+objectbench.width=286
17
+package.divider.horizontal=0.6004098360655737
18
+package.divider.vertical=0.7026022304832714
19
+package.editor.height=371
20
+package.editor.width=366
21
+package.editor.x=233
22
+package.editor.y=23
23
+package.frame.height=596
24 24
 package.frame.width=508
25 25
 package.numDependencies=3
26 26
 package.numTargets=6