Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java file called CompoundInterestYourLastName. Write a method called computeBalance( ) that computes the balance of a bank account with a given initial deposit,

Create a Java file called CompoundInterestYourLastName. Write a method called computeBalance( ) that computes the balance of a bank account with a given initial deposit, annual interest rate, after a given number of years for the investment. Assume interest is compounded yearly. The formula for determining compound interest (compounded yearly) is: A space equals space P space left parenthesis space 1 plus r space right parenthesis space to the power of t space where: A = the future value of the investment/loan, including interest P = the principal investment amount (the initial deposit or loan amount) r = the annual interest rate (decimal) t = the time the money is invested or borrowed for Create your method to accept three parameters in this order: initial deposit, annual interest rate as a decimal, after a given number of years. Your method should return a double value of the future value including interest. In your main method, run the following tests to verify your method is working correctly. System.out.printf("Your total is $%.2f", computeBalance(5000, .05, 10)); // should return $8144.47 System.out.printf(" Your total is $%.2f", computeBalance(2000, .03, 5)); // should return $2318.55 System.out.printf(" Your total is $%.2f", computeBalance(3000, .01, 10)); // should return $3313.87 Pay close attention to your parameters to make sure they match the test data! *Note: Your methods should have this exact signature line, including the correct spelling, capitalization and parameter types. Otherwise, when I run the test to check the file, your methods will fail and you'll have to revise. When you are finished with your file, save it. You will upload it to Blackboard after you implement unit testing in topic 5. This completed program is worth 20 points - 10 points for the program and 10 points for the JUnit tests. Help? Remember your order of operations and don't try to do it in one line. The order of operations is: Parentheses - (1+annual interest rate as a decimal) Exponents - (Math.pow(the results of the parenthesis, years) Multiply/Divide - Result of the Math.pow * the initial amount Add/Subtraction - not applicable,

Now retrieve CompoundInterestYourLastName. Create a JUnit Test case to test your method. Write three tests using the data and results below.

A hint: You can give your assertEquals method some leeway so you don't need the exact values by using this method:

assertEquals(double expected, double actual, double delta); Asserts that two doubles or floats are equal to within a positive delta.

If you ran your methods (with the main method without the printf( )), you'll see that you get several decimal points. One way that we can account for small differences is by giving the assertEquals method a delta - 0.01. This means that if the return result is within 0.01 of the expected value, return true. The assertion method would look something like:

assertEquals(expected, actual, 0.01);

Write assertion methods for the three examples below. Make sure that your assertion methods all pass.

System.out.printf("Your total is $%.2f", computeBalance(1000, .045, 3));

// should return $1141.17

System.out.printf(" Your total is $%.2f", computeBalance(2000, .03, 5));

// should return $2318.55

System.out.printf(" Your total is $%.2f", computeBalance(3000, .01, 10));

// should return $3313.87

Pay close attention to your parameters to make sure they match the test data!

When you are finished with your tests, upload and submit CompoundInterestYourLastName.java and CompoundInterestYourLastNameTest.java to Blackboard. This program is worth 20 points.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions