Browse Source

Done with my loops

Whitney Martinez 6 years ago
parent
commit
2bd1a84bac
5 changed files with 73 additions and 47 deletions
  1. BIN
      .DS_Store
  2. 43
    3
      TableUtilities.java
  3. 25
    37
      TriangleUtilities.java
  4. 0
    2
      TriangleUtilitiesTest.java
  5. 5
    5
      package.bluej

BIN
.DS_Store View File


+ 43
- 3
TableUtilities.java View File

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

+ 25
- 37
TriangleUtilities.java View File

@@ -1,11 +1,10 @@
1
+import java.util.*;
1 2
 
2 3
 public class TriangleUtilities {
3
-
4 4
     public static String getRow(int numberOfStars) {
5 5
         String line = "";
6
-
7
-        for(int i = 0; i <= numberOfStars; i++){
8
-            line = "*"+ line;
6
+        for(int i = 0; i < numberOfStars; i++){
7
+            line += "*";
9 8
         }
10 9
         return line;
11 10
 
@@ -14,13 +13,13 @@ public class TriangleUtilities {
14 13
     public static String getTriangle(int numberOfRows) {
15 14
 
16 15
         String line = "";
17
-    
18
-        for(int i=0; i < numberOfRows; i++){
19 16
 
20
-            for(int j=0; j <= i; j++){
21
-                line =  line + "*";
17
+        for(int i=1; i <= numberOfRows; i++){
18
+
19
+            for(int j=1; j <= i; j++){
20
+                line += "*";
22 21
             }
23
-            line =  line + "/n";
22
+            line += "\n";
24 23
         }
25 24
 
26 25
         return line;
@@ -28,42 +27,31 @@ public class TriangleUtilities {
28 27
     }
29 28
 
30 29
     public static String getSmallTriangle() {
31
-        return null;
32
-    }
30
+        String line = "";
33 31
 
34
-    public static String getLargeTriangle() {
35
-        return null;
36
-    }
32
+        for(int i=1; i <= 4; i++){
37 33
 
38
-    public void squares() 
39
-    {
40
-        int i,j;
41
-        for(i=1; i<=5; i++)
42
-        {
43
-            for(j=1; j<=4; j++)
44
-            {
45
-                System.out.print("*");
34
+            for(int j=1; j <= i; j++){
35
+                line += "*";
46 36
             }
47
-            System.out.println(" ");
37
+            line += "\n";
48 38
         }
39
+
40
+        return line;
41
+
49 42
     }
43
+    public static String getLargeTriangle() {
44
+        String line = "";
50 45
 
51
-      public void trying()
52
-        {
53
-            int i,j,k;
54
-            for(i=1; i<=5; i++)
55
-            {
56
-                for(j=4; j>=i; j--)
57
-                {
58
-                    System.out.print(" ");
59
-                }
60
-                for(k=1; k<=(2+j-1); k++)
61
-                {
62
-                    System.out.print("*");
63
-                }
64
-                System.out.println("");
46
+        for(int i=1; i <10; i++){
47
+            for(int j=1; j <= i; j++){
48
+                line += "*";
65 49
             }
50
+            line += "\n";
66 51
         }
52
+
53
+        return line;
67 54
     }
68 55
 
56
+}
69 57
 

+ 0
- 2
TriangleUtilitiesTest.java View File

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

+ 5
- 5
package.bluej View File

@@ -8,18 +8,18 @@ dependency2.type=UsesDependency
8 8
 dependency3.from=TriangleUtilitiesTest
9 9
 dependency3.to=TriangleUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=709
11
+editor.fx.0.height=712
12 12
 editor.fx.0.width=800
13
-editor.fx.0.x=559
14
-editor.fx.0.y=-876
13
+editor.fx.0.x=425
14
+editor.fx.0.y=27
15 15
 objectbench.height=156
16 16
 objectbench.width=273
17 17
 package.divider.horizontal=0.6008583690987125
18 18
 package.divider.vertical=0.7496159754224271
19 19
 package.editor.height=481
20 20
 package.editor.width=360
21
-package.editor.x=-129
22
-package.editor.y=-879
21
+package.editor.x=100
22
+package.editor.y=23
23 23
 package.frame.height=709
24 24
 package.frame.width=486
25 25
 package.numDependencies=3