Question

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 your main method, run the following tests to verify your method is working correctly.

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 datat!

*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.

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

This is the method you need to submit /use

public static double computeBalance(double balance, double rate, int years) {
    for(int i = 0; i < years; ++i) {
        balance *= (1 + rate);
    }
    return balance;
}

\color{blue}Below\;is\;the\;complete\;program\;if\;you\;are\;interested..

public class ComputeBalance {

    public static double computeBalance(double balance, double rate, int years) {
        for(int i = 0; i < years; ++i) {
            balance *= (1 + rate);
        }
        return balance;
    }

    public static void main(String[] args) {
        System.out.printf("Your total is $%.2f", computeBalance(1000, .045, 3));
        System.out.printf("\nYour total is $%.2f", computeBalance(2000, .03, 5));
        System.out.printf("\nYour total is $%.2f", computeBalance(3000, .01, 10));
    }

}

This is the method you need to submit /use

Add a comment
Know the answer?
Add Answer to:
JAVA Write a method called computeBalance( ) that computes the balance of a bank account with...
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
  • 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...

  • Bank Accounts Look at the Account class Account.java and write a main method in a different...

    Bank Accounts Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class. • Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an...

  • Develop a VI that computes the balance of a bank account (compounded yearly) at a given...

    Develop a VI that computes the balance of a bank account (compounded yearly) at a given interest rate with yearly monetary additions. Use the following base equation: X=P1+in Where X is end of year account balance, P is the initial account balance, i is the interest rate, and n is the number of years. NOTE: This equation does not account for additional yearly deposits! It is your job to figure out how to include that portion of the equation. User...

  • Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...

    Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...

  • 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 {    /* *...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

  • 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.

  • In JAVA using Netbeans Create a method called sumLastValues that will produce the sum of the...

    In JAVA using Netbeans Create a method called sumLastValues that will produce the sum of the last two values in an int variable. Your method should take as a parameter the integer to extract the last two values from. Your method should check to make sure that the int has at least two digits in it. If it does not your method should simply return-1 If it does extract the last two digits return their sum NOTE You are not...

  • 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...

  • Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.

    Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...

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