Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed lab #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
63 changes: 56 additions & 7 deletions NumberUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,80 @@


public class NumberUtilities {



public static String getRange(int stop) {
return null;
}

String result = "";

for(int i = 0; i < stop ; i++)
{
result = result + i;
}

return result;

}


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

}
return result;
}


public static String getRange(int start, int stop, int step) {
return null;

String result = "";
for(int i =start ; i<stop ; i+=step)
{
result = result + i;

}
return result;

}

public static String getEvenNumbers(int start, int stop) {
return null;

String result = "";
for(int i = start ; i<stop ; i++)
{
if(i%2 == 0)
{
result = result + i;
}
}
return result;
}


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


public static String getExponentiations(int start, int stop, int exponent) {
return null;
String result = "";
for(int i = start ; i<= stop ; i++)
{
result += (int)Math.pow(i, exponent);

}
return result;
}
}
1 change: 1 addition & 0 deletions NumberUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void testGetRangeForSmallRange() {

// : When
String actual = NumberUtilities.getRange(stop);


// : Then
Assert.assertEquals(expected, actual);
Expand Down
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
2 changes: 1 addition & 1 deletion README-TriangleUtilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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)





















19 changes: 16 additions & 3 deletions TableUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;

return getMultiplicationTable(5);
}

public static String getLargeMultiplicationTable() {
return null;

return getMultiplicationTable(10);
}

public static String getMultiplicationTable(int tableSize) {
return null;
String result = "";
for(int i = 1 ; i <= tableSize ; i++)
{
for(int j = 1; j<= tableSize; j++)
{
result = result + String.format("%3s",(i * j)) + "|";
}
result = result + "\n";
}

return result;
}

}
2 changes: 2 additions & 0 deletions TableUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void testGetMultiplicationTable() {
" 19 | 38 | 57 | 76 | 95 |114 |133 |152 |171 |190 |209 |228 |247 |266 |285 |304 |323 |342 |361 |380 |\n" +
" 20 | 40 | 60 | 80 |100 |120 |140 |160 |180 |200 |220 |240 |260 |280 |300 |320 |340 |360 |380 |400 |\n";
String actual = TableUtilities.getMultiplicationTable(20);
System.out.println(expected);
System.out.println(actual);
Assert.assertEquals(expected, actual);
}

Expand Down
23 changes: 18 additions & 5 deletions TriangleUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@
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;
return getTriangle(4);
}

public static String getLargeTriangle() {
return null;
return getTriangle(9);
}
}
Loading