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

Program complete #58

Open
wants to merge 3 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 @@ -3,26 +3,84 @@

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

}

}

return evenNumbers.toString();
}


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

StringBuilder oddNumbers = new StringBuilder();
for (int count = start; count < stop; count++) {
if (count % 2 == 1) {
oddNumbers.append(count);

}

}

return oddNumbers.toString();
}


public static String getSquareNumbers(int start, int stop, int step) {
return null;
StringBuilder squaredNumbers = new StringBuilder();
for (int count = start; count < stop; count += step) {

squaredNumbers.append(count * count);


}

return squaredNumbers.toString();
}


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

rangeNumbers.append(count);


}

return rangeNumbers.toString();
}


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

for (int count = start; count < stop; count += step) {
int exp = count;
for (int count2 = 1; count2 < exponent; count2++) {
exp = exp * count;

}
expoNumbers.append(exp);


}

return expoNumbers.toString();
}

public static String getRange(int stop) {
String result = NumberUtilities.getRange(0, stop, 1);
return result;
}

public static String getRange(int start, int stop) {
String result = NumberUtilities.getRange(start, stop, 1);
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,48 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;
StringBuilder table = new StringBuilder();
for (int count = 1; count <= 5; count++) {
for (int count2 = 1; count2 <= 5; count2++) {
String a = String.format("%3d |", count * count2);
table.append(a);

}
table.append("\n");

}

return table.toString();
}

public static String getLargeMultiplicationTable() {
return null;
StringBuilder table = new StringBuilder();
for (int count = 1; count <= 10; count++) {
for (int count2 = 1; count2 <= 10; count2++) {
String a = String.format("%3d |", count * count2);
table.append(a);

}
table.append("\n");

}

return table.toString();
}

public static String getMultiplicationTable(int tableSize) {
return null;
StringBuilder table = new StringBuilder();
for (int count = 1; count <= tableSize; count++) {
for (int count2 = 1; count2 <= tableSize; count2++) {
String a = String.format("%3d |", count * count2);
table.append(a);

}
table.append("\n");

}

return table.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 triangle = new StringBuilder();
for (int count = 1; count < numberOfRows; count++) {
for (int count2 = 0; count2 < count; count2++) {
triangle.append("*");

}
triangle.append("\n");
}
return triangle.toString();
}

public static String getRow(int numberOfStars) {
return null;
public static String getRow(int numberOfStars) {
StringBuilder row = new StringBuilder();
for (int count = 0; count < numberOfStars; count++) {
row.append("*");
}

return row.toString();
}

public static String getSmallTriangle() {
return null;
StringBuilder triangle = new StringBuilder();
for (int count = 1; count < 5; count++) {
for (int count2 = 0; count2 < count; count2++) {
triangle.append("*");

}
triangle.append("\n");
}
return triangle.toString();
}

public static String getLargeTriangle() {
return null;
StringBuilder triangle = new StringBuilder();
for (int count = 1; count < 11; count++) {
for (int count2 = 0; count2 < count; count2++) {
triangle.append("*");

}
triangle.append("\n");
}
return triangle.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ public void testGetRange2() {
Assert.assertEquals(expected, actual);
}

@Test
public void testGetRange3() {
// : Given
String expected = "012345678910";
int stop = 11;

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

// : Then
Assert.assertEquals(expected, actual);
}
@Test
public void testGetRange4() {
// : Given
String expected = "012345678910111213141516171819";
int start = 0;
int stop = 20;

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

// : Then
Assert.assertEquals(expected, actual);
}



Expand All @@ -51,7 +76,7 @@ public void testGetRange2() {
@Test
public void testGetEvenNumbers() {
// : Given
String expected = "5791113151719";
String expected = "681012141618";
int start = 5;
int stop = 20;

Expand All @@ -65,7 +90,7 @@ public void testGetEvenNumbers() {
@Test
public void testGetOddNumbers() {
// : Given
String expected = "681012141618";
String expected = "5791113151719";
int start = 5;
int stop = 20;
int step = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void testGetLargeTriangle() {
"******\n" +
"*******\n" +
"********\n" +
"*********\n";
"*********\n" +
"**********\n";
String actual = TriangleUtilities.getLargeTriangle();
Assert.assertEquals(expected, actual);
}
Expand Down