Question

Create a Java file called CompoundInterestYourLastName. Write a method called computeBalance( ) that computes the balance...

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("\nYour total is $%.2f", computeBalance(2000, .03, 5)); // should return $2318.55 System.out.printf("\nYour 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("\nYour total is $%.2f", computeBalance(2000, .03, 5));

// should return $2318.55

System.out.printf("\nYour 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN JAVA:

CompoundInterestYourLastName.java file:


public class CompoundInterestYourLastName {
   public static double computeBalance(double balance, double annualInterestRate, int years) {
       double totalAmount = balance;
       double interest ;
       for(int i = 1 ; i <= years ; i++) {
               interest = totalAmount * annualInterestRate ;
               totalAmount += interest ;
       }
       return totalAmount ;
   }
   public static void main(String[] args) {
      
       System.out.printf("Your total is $%.2f", computeBalance(1000, .045, 3));

       // should return $1141.17

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

       // should return $2318.55

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

       // should return $3313.87

   }

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Create a Java file called CompoundInterestYourLastName. Write a method called computeBalance( ) that computes the balance...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Write a method called computeBalance( ) that computes the balance of a bank account with...

    JAVA Write a method called computeBalance( ) that computes the balance of a bank account with a given initial balance and interest rate, after a given number of years. Assume interest is compounded yearly. You can use the standard calculator here to check your results (note that you'll have to change the dropdown to compound the interest yearly): http://www.thecalculatorsite.com/finance/calculators/compoundinterestcalculator.php Use a loop to control the iterations through the years in your method. Your method should return a double value. In...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

  • The following code computes the radius of a circle. Using static methods from the Math class...

    The following code computes the radius of a circle. Using static methods from the Math class complete the method that computes the radius of a circle using the formula  r2=(x-h)2 +(y-k)2 , given the (x,y) coordinates of one point on its circumference and the (h,k) coordinates of its center. public class Circle {    public static void main(String[] C)    {        double x1 =14.25;        double y1 =13.68;        double xCenter = 25.678;        double yCenter...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement...

    Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement two recursive methods and write JUnit tests for each one. You may write all three methods in the same class file. You are required to write Javadoc-style documentation for all of your methods, including the test methods. Procedure 1) Write method!! a recursive method to compare two Strings using alphabetical order as the natural order (case insensitive, DO NOT use the String class built-in...

  • In Java: Let's create a method that has parameters. Write a method, called returnHours that returns...

    In Java: Let's create a method that has parameters. Write a method, called returnHours that returns a string. Make the string from a string representing your name and a number representing the hours you spend sleeping, both are values that you pass in from the main. Create the variables to pass into the method call in main. Call the method and print the return value in main. Run and test it.

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT