From 06ecb770f1ffc62268322eebfc2d48d8abbf5fc3 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 25 Jun 2021 18:04:27 -0400 Subject: [PATCH] Code passed all tests --- NumberUtilities.java | 45 +++++++++++++++++++++++++++----- README-TableUtilities.md | 6 ++--- README-TriangleUtilities.md | 2 +- README.TXT | 0 README.md | 52 ++++++++++++++++++------------------- TableUtilities.java | 49 +++++++++++++++++++++++++++++++--- TriangleUtilities.java | 33 ++++++++++++++++++++--- 7 files changed, 143 insertions(+), 44 deletions(-) create mode 100644 README.TXT diff --git a/NumberUtilities.java b/NumberUtilities.java index 1d5ba50..9035fec 100644 --- a/NumberUtilities.java +++ b/NumberUtilities.java @@ -1,32 +1,63 @@ - +import java.lang.Math; public class NumberUtilities { public static String getRange(int stop) { - return null; + String x = ""; + for (int i = 0; i < stop; i++){ + x += i; + } + return x; } public static String getRange(int start, int stop) { - return null; + String x = ""; + for (int i = start; i < stop; i++){ + x += i; + } + return x; } public static String getRange(int start, int stop, int step) { - return null; + String x = ""; + int i = start; + while (i < stop) { + x += i; + i += step; + } + return x; } public static String getEvenNumbers(int start, int stop) { - return null; + String x = ""; + for (int i = start; i < stop; i++){ + if((i % 2) == 0){ + x += i; + } + } + return x; } public static String getOddNumbers(int start, int stop) { - return null; + String x = ""; + for (int i = start; i < stop; i++){ + if((i % 2) == 1){ + x += i; + } + } + return x; } public static String getExponentiations(int start, int stop, int exponent) { - return null; + String x = ""; + for (int i = start; i <= stop; i++){ + int a = (int)Math.pow(i,exponent); + x += a; + } + return x; } } diff --git a/README-TableUtilities.md b/README-TableUtilities.md index 535699c..99fc80d 100644 --- a/README-TableUtilities.md +++ b/README-TableUtilities.md @@ -39,7 +39,7 @@ ## `String getSmallMultiplicationTable()` * **Description** * Generate a `String` representation of a multiplication table whose dimensions are `4` by `4` - + ### Example 1 * Sample Script @@ -107,7 +107,7 @@ * **Description** * Generate a `String` representation of a multiplication table whose dimensions are `9` by `9` - + ### Example * Sample Script @@ -176,7 +176,7 @@ * **Description** * Given one integer, `width`, generate a `String` representation of a multiplication table whose dimensions are `width` by `width` - + ### Example 1 * Sample Script diff --git a/README-TriangleUtilities.md b/README-TriangleUtilities.md index d489661..5a345ae 100644 --- a/README-TriangleUtilities.md +++ b/README-TriangleUtilities.md @@ -125,7 +125,7 @@ * **Description** * Given one integer, `n`, generate a `String` representation of a triangle whose base height and width is equal to `n`. - + ### Example * Sample Script diff --git a/README.TXT b/README.TXT new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 4421908..9e733d9 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ -# Leon's Loopy Lab -* Read each of the following `README` files and complete each of the asks. - * [README-NumberUtilities.md](./README-NumberUtilities.md) - * [README-TriangleUtilities.md](./README-TriangleUtilities.md) - * [README-TableUtilities.md](./README-TableUtilities.md) - - - - - - - - - - - - - - - - - - - - - +# Leon's Loopy Lab +* Read each of the following `README` files and complete each of the asks. + * [README-NumberUtilities.md](./README-NumberUtilities.md) + * [README-TriangleUtilities.md](./README-TriangleUtilities.md) + * [README-TableUtilities.md](./README-TableUtilities.md) + + + + + + + + + + + + + + + + + + + + + diff --git a/TableUtilities.java b/TableUtilities.java index 03bf004..55ab37a 100644 --- a/TableUtilities.java +++ b/TableUtilities.java @@ -2,14 +2,57 @@ public class TableUtilities { public static String getSmallMultiplicationTable() { - return null; + String table = ""; + for (int i = 1; i <= 5; i++) { + for (int x = 1; x <= 5; x++) { + int b = i * x; + String z = String.valueOf(b); + String space = " "; + if (z.length() == 2) { + space = " "; + } + table += space + b + " |"; + } + table += "\n"; + } + return table; } public static String getLargeMultiplicationTable() { - return null; + String table = ""; + for (int i = 1; i <= 10; i++) { + for (int x = 1; x <= 10; x++) { + int b = i * x; + String z = String.valueOf(b); + String space = " "; + if (z.length() == 2) { + space = " "; + } else if (z.length() == 3){ + space = ""; + } + table += space + b + " |"; + } + table += "\n"; + } + return table; } public static String getMultiplicationTable(int tableSize) { - return null; + String table = ""; + for (int i = 1; i <= tableSize; i++) { + for (int x = 1; x <= tableSize; x++) { + int b = i * x; + String z = String.valueOf(b); + String space = " "; + if (z.length() == 2) { + space = " "; + } else if (z.length() == 3){ + space = ""; + } + table += space + b + " |"; + } + table += "\n"; + } + return table; } } diff --git a/TriangleUtilities.java b/TriangleUtilities.java index 8755fd0..71ddec6 100644 --- a/TriangleUtilities.java +++ b/TriangleUtilities.java @@ -3,19 +3,44 @@ public class TriangleUtilities { public static String getRow(int numberOfStars) { - return null; + String x = ""; + for(int i = 0; i < numberOfStars; i++) { + x += "*"; + } + return x; } public static String getTriangle(int numberOfRows) { - return null; + String a = ""; + for (int i = 0; i < numberOfRows; i++) { + for (int x = 0; x <= i; x++) { + a += "*"; + } + a += "\n"; + } + return a; } public static String getSmallTriangle() { - return null; + String a = ""; + for (int i = 0; i <= 3; i++) { + for (int x = 0; x <= i; x++) { + a += "*"; + } + a += "\n"; + } + return a; } public static String getLargeTriangle() { - return null; + String a = ""; + for (int i = 0; i < 9; i++) { + for (int x = 0; x <= i; x++) { + a += "*"; + } + a += "\n"; + } + return a; } }