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
43 changes: 28 additions & 15 deletions NumberUtilities.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@



public class NumberUtilities {

public static String getRange(int stop) {
return null;
public static String getEvenNumbers(int start, int stop) {
return start % 2 == 1 ?
getRange(++start, stop, 2) :
getRange(start, stop, 2);
}

public static String getRange(int start, int stop) {
return null;
public static String getOddNumbers(int start, int stop) {
return start % 2 == 0 ?
getRange(++start, stop, 2) :
getRange(start, stop, 2);
}


public static String getRange(int start, int stop, int step) {
return null;
public static String getSquareNumbers(int start, int stop, int step) {
return getExponentiations(start, stop, step, 2);
}

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

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

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

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

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

public static String getExponentiations(int start, int stop, int step, int exponent) {
int currentNumber = start;
StringBuilder range = new StringBuilder();
while (currentNumber < stop) {
range.append((int) Math.pow(currentNumber, exponent));
currentNumber += step;
}
return range.toString();
}
}

16 changes: 9 additions & 7 deletions NumberUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,34 +164,36 @@ public void testGetOddNumbersStartAndEndAtEven() {
// : Then
Assert.assertEquals(expected, actual);
}


//expected:<[4916253649]> but was:<[162536]>
@Test
public void testGetExponentiationNumbersForSquare() {
// : Given
String expected = "4916253649";
int start = 2;
int stop = 7;
int stop = 8;
int step = 1; //do not touch
int exponent = 2;

// : When
String actual = NumberUtilities.getExponentiations(start, stop, exponent);
String actual = NumberUtilities.getExponentiations(start, stop, step, exponent);

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


//expected:<1827[64]> but was:<182764[125]>
@Test
public void testGetExponentiationNumbersForCube() {
// : Given
String expected = "182764";
int start = 1;
int stop = 4;
int stop = 5;
int step = 1; //do not touch
int exponent = 3;

// : When
String actual = NumberUtilities.getExponentiations(start, stop, exponent);
String actual = NumberUtilities.getExponentiations(start, stop, step, exponent);

// : Then
Assert.assertEquals(expected, actual);
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
13 changes: 10 additions & 3 deletions TableUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

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 += String.format("%3s ",(i * j)) + "|";
}
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
20 changes: 16 additions & 4 deletions TriangleUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
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);
}
}