From 6aa70e1f5adac67a94adeafdcdfe071bc803a7a7 Mon Sep 17 00:00:00 2001 From: Bo Lee Date: Thu, 8 Feb 2018 14:46:21 -0500 Subject: [PATCH] Complete --- .DS_Store | Bin 0 -> 6148 bytes .../mastering_loops/NumberUtilities.java | 37 ++++++++++++-- .../mastering_loops/TableUtilities.java | 45 ++++++++++++++++-- .../mastering_loops/TriangleUtilities.java | 34 +++++++++++-- .../mastering_loops/NumberUtilitiesTest.java | 4 +- 5 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f0a9209f479ea197c6dfda6fc5763de85fe17ceb GIT binary patch literal 6148 zcmeHK&2G~`5T0#9>jWVpfz%)_z94Z3Q3@?Rph_Vmhe`z@T;KqxwPP!_2hiKUq`)HDfG>w%o!+kS{+9E;LC>f|52=l{J2)+#&6YWDWM`_pO3+Pt;3w}0G!_kQwW z`tb{jhcH|^Qm$&8!&ev?LQb6|j(FU|_&jFrdx23?VO_q!9GKD#1BQXs42bi=h6-$I zoGFw?2O9YV02VPU1-AHeAYyEdO^q{!n1L`A3RIy?KQWjJ$GENini^*cRX8#I_+WZv zre7#bu8#b+bSKtSXj;R7VIa#uL3JzQ{_mXq{?7)Po?*Z+@Lw^&ifyOeLP`2=T`Er8 vwKnt^Dn$6r6v_}Z`Z|_|xQeS#DVVc`0c>iVDZ~iG{1K2en8q;hR~h&XsqM@s literal 0 HcmV?d00001 diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java index 5a742c4..ebe19c5 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java @@ -1,28 +1,55 @@ package io.zipcoder.microlabs.mastering_loops; + + public class NumberUtilities { + + public static String getEvenNumbers(int start, int stop) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = start; i < stop; i+=2){ + myRange.append(i); + } + return myRange.toString(); + } public static String getOddNumbers(int start, int stop) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = start; i < stop; i+=2){ + myRange.append(i); + } + return myRange.toString(); } public static String getSquareNumbers(int start, int stop, int step) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = start; i < stop; i+=step){ + myRange.append((long)(Math.pow(i,2))); + } + return myRange.toString(); } public static String getRange(int start, int stop, int step) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = start; i < stop; i+=step){ + myRange.append(i); + } + return myRange.toString(); + + } public static String getExponentiations(int start, int stop, int step, int exponent) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = start; i < stop; i+=step){ + myRange.append((long)(Math.pow(i, exponent))); + } + return myRange.toString(); } } diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java index e27a826..a0c3f22 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java @@ -1,15 +1,54 @@ package io.zipcoder.microlabs.mastering_loops; + + +@SuppressWarnings("ALL") public class TableUtilities { public static String getSmallMultiplicationTable() { - return null; + StringBuilder myRange = new StringBuilder(); + + for (int i = 1; i <=5; i++){ + for (int n = 1; n <= 5; n++) { + + myRange.append(String.format("%3d |", n * i)); + } + myRange.append("\n"); + } + + return myRange.toString(); } + + public static String getLargeMultiplicationTable() { - return null; + StringBuilder myRange = new StringBuilder(); + + for (int i = 1; i <=10; i++){ + for (int n = 1; n <= 10; n++) { + + myRange.append(String.format("%3d |", n * i)); + + } + myRange.append("\n"); + + } + + return myRange.toString(); } public static String getMultiplicationTable(int tableSize) { - return null; + StringBuilder myRange = new StringBuilder(); + + for (int i = 1; i <= tableSize; i++){ + for (int n = 1; n <= tableSize; n++) { + + myRange.append(String.format("%3d |", n * i)); + + } + myRange.append("\n"); + + } + + return myRange.toString(); } } diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java index 0c7cd35..2e815a7 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java @@ -3,18 +3,44 @@ public class TriangleUtilities { public static String getTriangle(int numberOfRows) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = 1; i < numberOfRows; i++){ + for (int n = 1; n <= i; n++) { + myRange.append("*"); + } + myRange.append("\n"); + } + return myRange.toString(); } public static String getRow(int numberOfStars) { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = 0; i < numberOfStars; i++){ + myRange.append("*"); + } + return myRange.toString(); + } public static String getSmallTriangle() { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = 1; i <= 4; i++){ + for (int n = 1; n <= i; n++) { + myRange.append("*"); + } + myRange.append("\n"); + } + return myRange.toString(); } public static String getLargeTriangle() { - return null; + StringBuilder myRange = new StringBuilder(); + for (int i = 1; i < 10; i++){ + for (int n = 1; n <= i; n++) { + myRange.append("*"); + } + myRange.append("\n"); + } + return myRange.toString(); } } diff --git a/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java b/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java index e579b43..2793098 100644 --- a/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java +++ b/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java @@ -65,10 +65,10 @@ public void testGetEvenNumbers() { @Test public void testGetOddNumbers() { // : Given - String expected = "681012141618"; + String expected = "5791113151719"; int start = 5; int stop = 20; - int step = 5; + // : When String actual = NumberUtilities.getOddNumbers(start, stop);