Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Interest {
- public static void main(String[] args) {
- System.out.println("We will calcuate your bank balance if compounded daily, monthly, and yearly.");
- //gather input
- Scanner s = new Scanner(System.in);
- System.out.println("Enter starting balance.");
- double startBal = s.nextInt();
- System.out.println("Enter number of years your balance is compounded.");
- int year = s.nextInt();
- System.out.println("Enter your interest rate.");
- //yearly compounding
- double rate = s.nextDouble();
- double yearlyRate = rate;
- //monthly compounding
- double monthlyRate = yearlyRate/12;
- double numMonths = year * 12;
- //daily compounding
- double dailyRate = yearlyRate/365;
- double numDays = year * 365;
- double newBal = startBal;
- for(int y = 0; y < year; y++ ) {
- double interest = rate*startBal;
- startBal = interest + startBal;
- }
- double mBal = startBal;
- for(int i = 0; i < numMonths; i++) {
- double mInt = monthlyRate*startBal;
- mBal = mInt + mBal;
- }
- double dBal = startBal;
- for(int x = 0; x < numDays; x++) {
- double dInt = dailyRate*startBal;
- dBal = dInt + dBal;
- }
- System.out.printf("Your yearly ending balance is $%1.2f\n ", startBal);
- System.out.printf("Your monthly ending balance is $%1.2f\n ", mBal);
- System.out.printf("Your daily ending balance is $%1.2f\n ", dBal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement