From d66d8eb2420fb1f9bd181da884db2cb724bd584b Mon Sep 17 00:00:00 2001 From: NickJHower <37489349+nickj-h@users.noreply.github.com> Date: Mon, 26 Sep 2022 15:55:25 -0400 Subject: [PATCH 1/4] Add files via upload --- .../algorithms/math/CompoundInterest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java diff --git a/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java b/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java new file mode 100644 index 000000000..a584904de --- /dev/null +++ b/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java @@ -0,0 +1,13 @@ +package com.williamfiset.algorithms.math; + +public class CompoundInterest { + public static double CompoundInterest(double principalAmount, double interestRateDecimal, double compoundsPerYear, double totalYears) { + double unroundedNum = (principalAmount * Math.pow((1+(interestRateDecimal/compoundsPerYear)),compoundsPerYear*totalYears)); + //rounds to the nearest cent + return Math.round(unroundedNum*100.00)/100.00; + } + public static void main(String[] args) { + System.out.println(CompoundInterest(100,0.12,12,2)); + System.out.println(CompoundInterest(2001,0.21,4,8)); + } +} From d402daef436dd166bfbaf82f3fb9464ecb13e560 Mon Sep 17 00:00:00 2001 From: NickJHower <37489349+nickj-h@users.noreply.github.com> Date: Mon, 26 Sep 2022 15:57:18 -0400 Subject: [PATCH 2/4] Add files via upload --- .../algorithms/math/CompoundInterestTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java diff --git a/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java b/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java new file mode 100644 index 000000000..f10b3c5f9 --- /dev/null +++ b/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java @@ -0,0 +1,18 @@ +package com.williamfiset.algorithms.math; + +import com.williamfiset.algorithms.other.BitManipulations; +import org.junit.Test; + +import static com.google.common.truth.Truth.assertThat; + +import java.util.*; + +public class CompoundInterestTest { + @Test + public void testInterest() { + assertThat(CompoundInterest.CompoundInterest(120,0.1,12,2)).isEqualTo(146.45); + assertThat(CompoundInterest.CompoundInterest(.5,0.25,4,12)).isEqualTo(9.18); + assertThat(CompoundInterest.CompoundInterest(12000,0.05,1,5)).isEqualTo(15315.38); + assertThat(CompoundInterest.CompoundInterest(10,0.1,2,10)).isEqualTo(26.53); + } +} From 06a3e63aadf6da657959edc900f0f78a23c2a300 Mon Sep 17 00:00:00 2001 From: NickJHower <37489349+nickj-h@users.noreply.github.com> Date: Mon, 26 Sep 2022 15:58:09 -0400 Subject: [PATCH 3/4] Update CompoundInterestTest.java --- .../com/williamfiset/algorithms/math/CompoundInterestTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java b/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java index f10b3c5f9..2b2c9b78c 100644 --- a/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java +++ b/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java @@ -1,6 +1,5 @@ package com.williamfiset.algorithms.math; -import com.williamfiset.algorithms.other.BitManipulations; import org.junit.Test; import static com.google.common.truth.Truth.assertThat; From 888940738f07d0dcf768014079ed87d9508ceb8b Mon Sep 17 00:00:00 2001 From: nickh Date: Mon, 26 Sep 2022 16:16:14 -0400 Subject: [PATCH 4/4] validating files --- .../java/com/williamfiset/algorithms/math/CompoundInterest.java | 1 + .../com/williamfiset/algorithms/math/CompoundInterestTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java b/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java index a584904de..7bdf884ad 100644 --- a/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java +++ b/src/main/java/com/williamfiset/algorithms/math/CompoundInterest.java @@ -7,6 +7,7 @@ public static double CompoundInterest(double principalAmount, double interestRat return Math.round(unroundedNum*100.00)/100.00; } public static void main(String[] args) { + //example cases System.out.println(CompoundInterest(100,0.12,12,2)); System.out.println(CompoundInterest(2001,0.21,4,8)); } diff --git a/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java b/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java index 2b2c9b78c..f8e0354e6 100644 --- a/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java +++ b/src/test/java/com/williamfiset/algorithms/math/CompoundInterestTest.java @@ -8,6 +8,7 @@ public class CompoundInterestTest { @Test + //example tests public void testInterest() { assertThat(CompoundInterest.CompoundInterest(120,0.1,12,2)).isEqualTo(146.45); assertThat(CompoundInterest.CompoundInterest(.5,0.25,4,12)).isEqualTo(9.18);