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 #54

Open
wants to merge 2 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,68 @@


public class NumberUtilities {


public static String getEvenNumbers(int start, int stop) {
return null;
StringBuilder evenNumbers = new StringBuilder();
for (int i = start; i < stop ; i++) {
if(i % 2 == 0)
{
evenNumbers.append(i);
}

}


return evenNumbers.toString();

}


public static String getOddNumbers(int start, int stop) {
return null;
StringBuilder builderOddNumbers = new StringBuilder();
for (int i = start; i < stop ; i++) {
if(!(i % 2 == 0))
{
builderOddNumbers.append(i);
}

}


return builderOddNumbers.toString();

}


public static String getSquareNumbers(int start, int stop, int step) {
return null;
StringBuilder squareNumbersBuilder = new StringBuilder();
for (int i = start; i <stop ; i = i + step) {
int square = i * i;
squareNumbersBuilder.append(square);
}
return squareNumbersBuilder.toString();
}


public static String getRange(int start, int stop, int step) {
return null;
StringBuilder getRangeBuilder = new StringBuilder();
for (int i = start; i <stop ; i = i + step) {

getRangeBuilder.append(i);
}
return getRangeBuilder.toString();
}


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

StringBuilder exponentBuilder = new StringBuilder();
for (int i = start; i < stop ; i = i + step){
long exponentiatedValue = (long)Math.pow(i, exponent);
exponentBuilder.append(exponentiatedValue);
}

return exponentBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,43 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;
StringBuilder smallMultiBuilder = new StringBuilder();
for (int i = 1; i <= 5; i++) {

for (int w = 1; w <= 5; w++) {
int productIW = i * w;
smallMultiBuilder.append(String.format("%3d |", productIW));
}
smallMultiBuilder.append("\n");
}
return smallMultiBuilder.toString();
}

public static String getLargeMultiplicationTable() {
return null;
StringBuilder largeMultiplicationBuilder = new StringBuilder();
for (int i = 1; i <= 10; i++) {
for (int w = 1; w <= 10; w++) {
int productIW = i * w;
largeMultiplicationBuilder.append(String.format("%3d |", productIW));
}
largeMultiplicationBuilder.append("\n");
}
return largeMultiplicationBuilder.toString();

}

public static String getMultiplicationTable(int tableSize) {
return null;
StringBuilder multiplicationBuilder = new StringBuilder();
for (int i = 1; i <= 20; i++) {

for (int w = 1; w <= 20; w++) {
int productIW = (i * w);
multiplicationBuilder.append(String.format("%3d |", productIW));

}
multiplicationBuilder.append("\n");

}
return multiplicationBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,47 @@
public class TriangleUtilities {

public static String getTriangle(int numberOfRows) {
return null;
StringBuilder triangleBuilder = new StringBuilder();

for (int i = 1; i <= numberOfRows-1; i++) {
for (int w = 1; w <= i ; w++) {
triangleBuilder.append("*");
}
triangleBuilder.append("\n");
}

return triangleBuilder.toString();
}

public static String getRow(int numberOfStars) {
return null;

StringBuilder asteriskRowBuild = new StringBuilder();
for(int i = 1; i <= numberOfStars; i++) {
asteriskRowBuild.append("*");
}
return asteriskRowBuild.toString();
}

public static String getSmallTriangle() {
return null;

StringBuilder smallTriangle = new StringBuilder();
for (int i =1; i <= 4; i++) {
for (int w = 1; w <= i; w ++) {
smallTriangle.append("*");
}
smallTriangle.append("\n");
}
return smallTriangle.toString();
}

public static String getLargeTriangle() {
return null;
StringBuilder largeTriangle = new StringBuilder();
for (int i =1; i <= 9; i++) {
for (int w = 1; w <= i; w++) {
largeTriangle.append("*");
}
largeTriangle.append("\n");
}
return largeTriangle.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testGetRange2() {
@Test
public void testGetEvenNumbers() {
// : Given
String expected = "5791113151719";
String expected = "681012141618";
int start = 5;
int stop = 20;

Expand All @@ -65,10 +65,11 @@ public void testGetEvenNumbers() {
@Test
public void testGetOddNumbers() {
// : Given
String expected = "681012141618";
String expected = "5791113151719";
int start = 5;
int stop = 20;
int step = 5;
//
// int step = 5;

// : When
String actual = NumberUtilities.getOddNumbers(start, stop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void getRow() {
@Test
public void getTriangleTest1() {
String expected =
"*\n" +
"*\n" +
"**\n" +
"***\n" +
"****\n" +
Expand All @@ -34,7 +34,7 @@ public void getTriangleTest1() {
@Test
public void getTriangleTest2() {
String expected =
"*\n" +
"*\n" +
"**\n" +
"***\n" +
"****\n";
Expand Down