This is my assaigment:

Write a program that prompts the user for a beginning bank balance and an interest rate. The program will display the value of the account at the end of each year for 10 years. The output should show the value of the account for three different methods of compounding interest:

1) Annually: The interest is added once per year, at the end of the year. You can assume that the interest is posted exactly one year from the date of deposit.

2) Monthly: The interest is added once per month, at the end of the month. You can assume that interest is posted exactly one month after the date of deposit. Hint: Be sure to adjust the interest rate for the time period of the interest. If the rate is 5%, you must use (5/12)% in the monthly case.

3)Daily: The interest is added once per day, at the end of the day. You do not need to worry about leap years, assume that all years have 365 days. Hint: Be sure to adjust the interest rate for the time period of the interest. If the rate is 5%, you must use (5/365)% in the daily case.

Your program should allow the user to perform the calculation multiple times for different starting balances. A negative starting balance indicates that the user is done.

import java.util.Scanner;
import java.text.DecimalFormat;


public class TestBankInterest {

public static void main(String[] args) {

    double balance, interest, newBalance;

    Scanner keyboard = new Scanner(System.in);
    DecimalFormat formatter = new DecimalFormat("#0.00");

    System.out.println("What is your account's starting balance? ");
    balance = keyboard.nextDouble();

    System.out.println("What is the interest");
    interest = keyboard.nextDouble();

    for (int i = 0; i <= 12; i++) {

        newBalance = balance + (interest / 100) * balance;
        System.out.println("Month " + i + " = " + newBalance);
    }

}

}

My problem is that I don't know how to figure out the formula for Annually, Yearly, or Daily for example;

     newBalance = balance + (interest/100) * balance

Also, I'm confuss because I don't know if I should ask the user if they want to do it monthly or annually or daily
any help will be a biiiggggg help..
Thank You

Ps: I wants us to use loop ..in fact, 3 loops will be the answer for this

keep a variable somewhere that stores the last time you updated the intrest. best in a txtfile or something, but for the time being, just in the 'running application'.

for year: save 2013

include a check -> if date equals january first, check the current year against the stored year. if NOT equal -> overwrite the stored year by the current year and add the intrest.

for month: save the current month:
include a check -> if day of month equals 1, check the month against the one stored. NOT equal -> ...

Also, I'm confuss because I don't know if I should ask the user if they want to do it monthly or annually or daily

I think your assignment does want a user input for what method(annually,monthly,daily) compound interest the user wants.

create annually, monthly, daily methods. then call in the main method if user wants to use whichever method of compound interest

if(annually) then 
    execute annually method;

Likewise for monthly and daily.

Ask your lecturer/tutor about your confusions. they will surely clear your doubts :)

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.