Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Christian Grant
- // CIS 150AB 31662
- // Business P4.9 Online Bank
- import java.util.Scanner;
- public class OnlineBank
- {
- public static void main(String[] args)
- {
- // Instantiate the input system
- Scanner in = new Scanner(System.in);
- // Grab the initial balance from the user
- System.out.print("Initial balance: ");
- double initialBalance = in.nextDouble();
- // Grab the interest from the user
- System.out.print("Annual interest rate in percent: ");
- double initialInterest = in.nextDouble();
- // Compute the annual interest
- double interest = initialInterest / 100;
- // Compute the monthly interest
- double monthlyInterest = interest / 12;
- // Compute the first month with interest
- double firstInterest = initialBalance * monthlyInterest;
- double firstCompound = firstInterest + initialBalance;
- // Compute the second month with compound interest
- double secondInterest = firstCompound * monthlyInterest;
- double secondCompound = secondInterest + firstCompound;
- // Computer the third month with compound interest
- double thirdInterest = secondCompound * monthlyInterest;
- double thirdCompound = thirdInterest + secondCompound;
- // Output the compounded interest for the first three months
- System.out.printf("After first month: %.2f", firstCompound);
- System.out.printf("\nAfter second month: %.2f", secondCompound);
- System.out.printf("\nAfter third month: %.2f", thirdCompound);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement