From 5b6ca786229b33a7eff8c5eb8f2152324709b543 Mon Sep 17 00:00:00 2001 From: Maira Botelho Date: Fri, 18 Oct 2019 16:08:50 -0400 Subject: [PATCH] Program Works --- NumberUtilities.java | 60 +++++++++++++++++++++++++++++++++++++----- TableUtilities.java | 20 +++++++++++--- TriangleUtilities.java | 23 +++++++++++----- package.bluej | 38 +++++++++++++------------- 4 files changed, 105 insertions(+), 36 deletions(-) diff --git a/NumberUtilities.java b/NumberUtilities.java index 1d5ba50..b9c5910 100644 --- a/NumberUtilities.java +++ b/NumberUtilities.java @@ -4,29 +4,75 @@ public class NumberUtilities { public static String getRange(int stop) { - return null; + String result = ""; + + for (int x = 0; x < stop; x++){ + result = result + Integer.toString(x); + } + return result; } public static String getRange(int start, int stop) { - return null; + String result = ""; + + for (int x = start; x < stop; x++){ + result = result + Integer.toString(x); + } + return result; } - public static String getRange(int start, int stop, int step) { - return null; + String result = ""; + + for (int x = start; x < stop; x++){ + + if( x % step == 0 ){ + result = result + Integer.toString(x); + } + } + return result; } public static String getEvenNumbers(int start, int stop) { - return null; + String result = ""; + + for (int x = start; x < stop; x++){ + + if( x % 2 == 0 ){ + result = result + Integer.toString(x); + } + } + return result; } public static String getOddNumbers(int start, int stop) { - return null; + String result = ""; + + for (int x = start; x < stop; x++){ + + if( x % 2 != 0 ){ + result = result + Integer.toString(x); + } + } + return result; } public static String getExponentiations(int start, int stop, int exponent) { - return null; + String result = ""; + int num = 0; + + for (int x = start; x <= stop; x++){ + + num = x; + + for(int y = 1; y < exponent; y++){ + num = num * x ; + } + + result = result + Integer.toString(num); + } + return result; } } diff --git a/TableUtilities.java b/TableUtilities.java index 03bf004..4ac51ba 100644 --- a/TableUtilities.java +++ b/TableUtilities.java @@ -1,15 +1,27 @@ public class TableUtilities { - public static String getSmallMultiplicationTable() { - return null; + public static String getSmallMultiplicationTable() { + return getMultiplicationTable(5); } public static String getLargeMultiplicationTable() { - return null; + return getMultiplicationTable(10); } public static String getMultiplicationTable(int tableSize) { - return null; + String result = ""; + int num; + + for( int row = 1; row <= tableSize; row++){ + for( int times = 1; times <= tableSize; times++){ + num = row * times; + result+= String.format("%3d", num) + " |"; + + } + result = result + "\n"; + } + + return result; } } diff --git a/TriangleUtilities.java b/TriangleUtilities.java index 8755fd0..07acdd5 100644 --- a/TriangleUtilities.java +++ b/TriangleUtilities.java @@ -1,21 +1,32 @@ - public class TriangleUtilities { public static String getRow(int numberOfStars) { - return null; + String result = ""; + + for (int x = 0; x < numberOfStars; x++){ + result = result + "*"; + } + return result; } public static String getTriangle(int numberOfRows) { - return null; + String result = ""; + + for (int row = 1; row < numberOfRows + 1 ; row++){ + for(int stars = 0; stars < row; stars++){ + result = result + "*"; + } + result = result + "\n"; + } + return result; } - public static String getSmallTriangle() { - return null; + return getTriangle(4); } public static String getLargeTriangle() { - return null; + return getTriangle(9); } } diff --git a/package.bluej b/package.bluej index 028bdd0..5c165f5 100644 --- a/package.bluej +++ b/package.bluej @@ -1,27 +1,27 @@ #BlueJ package file -dependency1.from=NumberUtilitiesTest -dependency1.to=NumberUtilities +dependency1.from=TriangleUtilitiesTest +dependency1.to=TriangleUtilities dependency1.type=UsesDependency -dependency2.from=TriangleUtilitiesTest -dependency2.to=TriangleUtilities +dependency2.from=TableUtilitiesTest +dependency2.to=TableUtilities dependency2.type=UsesDependency -dependency3.from=TableUtilitiesTest -dependency3.to=TableUtilities +dependency3.from=NumberUtilitiesTest +dependency3.to=NumberUtilities dependency3.type=UsesDependency -editor.fx.0.height=722 -editor.fx.0.width=800 -editor.fx.0.x=537 -editor.fx.0.y=28 -objectbench.height=164 -objectbench.width=484 +editor.fx.0.height=1016 +editor.fx.0.width=1267 +editor.fx.0.x=198 +editor.fx.0.y=-1041 +objectbench.height=154 +objectbench.width=435 package.divider.horizontal=0.6 -package.divider.vertical=0.7560627674750356 -package.editor.height=523 -package.editor.width=382 -package.editor.x=20 -package.editor.y=57 -package.frame.height=759 -package.frame.width=508 +package.divider.vertical=0.825 +package.editor.height=752 +package.editor.width=341 +package.editor.x=0 +package.editor.y=0 +package.frame.height=978 +package.frame.width=459 package.numDependencies=3 package.numTargets=6 package.showExtends=true