Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions NumberUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,62 @@
public class NumberUtilities {

public static String getRange(int stop) {
return null;
String res = "";
for(int i = 0; i < stop; i++){
res += i;
}
return res;
}

public static String getRange(int start, int stop) {
return null;
String res = "";
Copy link

@Git-Leon Git-Leon Jun 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

violation of DRY principle.
Please make call to the relative template method.

Method definition suggestion 👇🏽

public static String getRange(int start, int stop) {
    return getRange(start, stop, 1);
}

for(int i = start; i < stop; i++){
res += i;
}
return res;
}


public static String getRange(int start, int stop, int step) {
return null;
String res = "";
for(int i = start; i < stop; i += step){
res += i;
}
return res;
}

public static String getEvenNumbers(int start, int stop) {
return null;
String res = "";
for(int i = start; i < stop; i++){
if(i % 2 == 0){
res += i;
}
}
return res;
}


public static String getOddNumbers(int start, int stop) {
return null;
String res = "";
for(int i = start; i < stop; i++){
if(i % 2 != 0){
res += i;
}
}
return res;
}


public static String getExponentiations(int start, int stop, int exponent) {
return null;
String res = "";
int calculatedValue;
for(int i = start; i <= stop; i++){
calculatedValue = i;
for(int j = 1; j < exponent; j++){
calculatedValue *= i;
}
res += calculatedValue;
}
return res;
}
}
6 changes: 3 additions & 3 deletions README-TableUtilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -107,7 +107,7 @@
* **Description**
* Generate a `String` representation of a multiplication table whose dimensions are `9` by `9`

### Example
* Sample Script

Expand Down Expand Up @@ -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

Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)





















47 changes: 43 additions & 4 deletions TableUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,53 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;
String tableResult = "";
int stringLength = 0;
for(int i = 1; i <= 5; i++){
for(int j = 1; j <= 5; j++){
//tableResult += " ";
stringLength = String.valueOf(i * j).length();
for(int k = 0; k < 3 - stringLength; k++){
tableResult += " ";
}
tableResult += (i * j) + " |";
}
tableResult += "\n";
}
return tableResult;
}

public static String getLargeMultiplicationTable() {
return null;
String tableResult = "";
int stringLength = 0;
for(int i = 1; i <= 10; i++){
for(int j = 1; j <= 10; j++){
//tableResult += " ";
stringLength = String.valueOf(i * j).length();
for(int k = 0; k < 3 - stringLength; k++){
tableResult += " ";
}
tableResult += (i * j) + " |";
}
tableResult += "\n";
}
return tableResult;
}

public static String getMultiplicationTable(int tableSize) {
return null;
String tableResult = "";
int stringLength = 0;
for(int i = 1; i <= tableSize; i++){
for(int j = 1; j <= tableSize; j++){
//tableResult += " ";
stringLength = String.valueOf(i * j).length();
for(int k = 0; k < 3 - stringLength; k++){
tableResult += " ";
}
tableResult += (i * j) + " |";
}
tableResult += "\n";
}
return tableResult;
}
}
}
2 changes: 2 additions & 0 deletions TableUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void testGetSmallMultiplicationTable() {
" 5 | 10 | 15 | 20 | 25 |\n";

String actual = TableUtilities.getSmallMultiplicationTable();
System.out.println(expected);
System.out.println(actual);
Assert.assertEquals(expected, actual);
}

Expand Down
33 changes: 29 additions & 4 deletions TriangleUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,44 @@
public class TriangleUtilities {

public static String getRow(int numberOfStars) {
return null;
String result = "";
for(int i = 0; i < numberOfStars; i++){
result += "*";
}
return result;
}

public static String getTriangle(int numberOfRows) {
return null;
String result = "";
for(int i = 0; i < numberOfRows; i++){
for(int j = 0; j <= i; j++){
result += "*";
}
result += "\n";
}
return result;
}


public static String getSmallTriangle() {
return null;
String result = "";
for(int i = 0; i < 4; i++){
for(int j = 0; j <= i; j++){
result += "*";
}
result += "\n";
}
return result;
}

public static String getLargeTriangle() {
return null;
String result = "";
for(int i = 0; i < 9; i++){
for(int j = 0; j <= i; j++){
result += "*";
}
result += "\n";
}
return result;
}
}
Loading