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

first commit almost done #64

Open
wants to merge 5 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 @@ -5,7 +5,10 @@
/**
* Created by leon on 1/31/18.
*/
public class MainApp {
public class MainApp extends TableUtilities{
public static void main(String[] args) {
TableUtilities result = new TableUtilities();
System.out.print(result.getMultiplicationTable(20));

}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,66 @@
package io.zipcoder.microlabs.mastering_loops;


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

return numList.toString();
}

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

return numList.toString();
}

public static String getSquareNumbers(int start, int stop, int step) {
return null;
StringBuilder numList = new StringBuilder();
for (int i = start; i < stop; i += step) {
int x = (int) Math.pow(i, 2);
numList.append(String.valueOf(x));
}

return numList.toString();
}

public static String getRange(int start) {
return null;
public static String getRange(int stop) {
StringBuilder numList = new StringBuilder();
for (int i = 0; i < stop; i++)
numList.append(String.valueOf(i));
return numList.toString();
}

public static String getRange(int start, int stop) {
return null;
StringBuilder numList = new StringBuilder();
for (int i = start; i < stop; i++)
numList.append(String.valueOf(i));
return numList.toString();
}


public static String getRange(int start, int stop, int step) {
return null;
StringBuilder numList = new StringBuilder();
for (int i = start; i < stop; i+=step)
numList.append(String.valueOf(i));
return numList.toString();
}


public static String getExponentiations(int start, int stop, int step, int exponent) {
return null;
StringBuilder numList = new StringBuilder();
for (int i = start; i < stop; i += step) {
int x = (int) Math.pow(i, exponent);
numList.append(String.valueOf(x));
}

return numList.toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
package io.zipcoder.microlabs.mastering_loops;

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;
/**
*
* @return a formatted multiplication table of various sizes
*/

public String getSmallMultiplicationTable() {
StringBuilder smallTable = new StringBuilder();
for (int i = 1; i < 6; i++) {
StringBuilder grow = new StringBuilder();
for (int a = 1; a < 6; a++) {
int b = a * i;
grow.append(String.format("%3d", b)).append(" |");
}

smallTable.append(grow).append("\n");
}

return smallTable.toString();
}

public static String getLargeMultiplicationTable() {
return null;
public String getLargeMultiplicationTable() {
StringBuilder bigTable = new StringBuilder();
for (int i = 1; i < 11; i++) {
StringBuilder grow = new StringBuilder();
for (int a = 1; a < 11; a++) {
int b = a * i;
grow.append(String.format("%3d", b)).append(" |");
}

bigTable.append(grow).append("\n");
}

return bigTable.toString();
}

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

table.append(grow).append("\n");
}

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

public static String getTriangle(int numberOfRows) {
return null;
StringBuilder newTriangle = new StringBuilder("*\n");
StringBuilder newLine = new StringBuilder("*");
int counter = 1;
while (counter < numberOfRows - 1) {
newLine.append("*");
newTriangle.append(newLine).append("\n");
counter++;
}

return newTriangle.toString();
}

public static String getRow(int numberOfStars) {
return null;
StringBuilder star = new StringBuilder();
int counter = 1;
while (counter <= numberOfStars) {
star.append("*");
counter++;
}

return star.toString();
}

public static String getSmallTriangle() {
return null;
StringBuilder newTriangle = new StringBuilder("*\n");
StringBuilder newLine = new StringBuilder("*");
int counter = 1;
while (counter < 4) {
newLine.append("*");
newTriangle.append(newLine).append("\n");
counter++;
}

return newTriangle.toString();
}

public static String getLargeTriangle() {
return null;
StringBuilder newTriangle = new StringBuilder("*\n");
StringBuilder newLine = new StringBuilder("*");
int counter = 1;
while (counter < 9) {
newLine.append("*");
newTriangle.append(newLine).append("\n");
counter++;
}

return newTriangle.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class NumberUtilitiesTest {
public void testGetRange1A() {
// : Given
String expected = "0123456789";
int stop = 11;
int stop = 10;

// : When
String actual = NumberUtilities.getRange(stop);
Expand Down Expand Up @@ -87,7 +87,7 @@ public void testGetRange2B() {
@Test
public void testGetRange3B() {
// : Given
String expected = "100101103104105106107108109";
String expected = "100101102103104105106107108109";
int start = 100;
int stop = 110;

Expand Down Expand Up @@ -173,7 +173,7 @@ public void testGetRange3C() {
@Test
public void testGetEvenNumbers() {
// : Given
String expected = "5791113151719";
String expected = "681012141618";
int start = 5;
int stop = 20;

Expand All @@ -187,7 +187,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 @@ -7,6 +7,8 @@
* Created by leon on 1/31/18.
*/
public class TableUtilitiesTest {

TableUtilities table = new TableUtilities();
@Test
public void testGetLargeMultiplicationTable() {
String expected =
Expand All @@ -21,7 +23,7 @@ public void testGetLargeMultiplicationTable() {
" 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |\n" +
" 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |\n";

String actual = TableUtilities.getLargeMultiplicationTable();
String actual = table.getLargeMultiplicationTable();
Assert.assertEquals(expected, actual);
}

Expand All @@ -35,7 +37,7 @@ public void testGetSmallMultiplicationTable() {
" 4 | 8 | 12 | 16 | 20 |\n" +
" 5 | 10 | 15 | 20 | 25 |\n";

String actual = TableUtilities.getSmallMultiplicationTable();
String actual = table.getSmallMultiplicationTable();
Assert.assertEquals(expected, actual);
}

Expand All @@ -62,7 +64,7 @@ public void testGetMultiplicationTable() {
" 18 | 36 | 54 | 72 | 90 |108 |126 |144 |162 |180 |198 |216 |234 |252 |270 |288 |306 |324 |342 |360 |\n" +
" 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);
String actual = table.getMultiplicationTable(20);
Assert.assertEquals(expected, actual);
}

Expand Down