Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class InterestCalculator2
- {
- public static void main(String arg[]){
- System.out.println("Please enter savings target");
- double initialBalance = 10000;
- double currentBalance = 0;
- System.out.println("The initial balance is £" + initialBalance);
- Scanner scan = new Scanner(System.in);
- double SavingsTarget = scan.nextDouble();
- currentBalance = initialBalance + interestOn (initialBalance);
- System.out.println("The balance after 1 year is £" + currentBalance);
- if (currentBalance > SavingsTarget)
- {
- System.out.println("Congratulations, your savings target has been reached");
- }
- currentBalance = currentBalance + interestOn (currentBalance);
- System.out.println("The balance after 2 years is £" + currentBalance);
- if (currentBalance > SavingsTarget)
- {
- System.out.println("Congratulations, your savings target has been reached");
- }
- currentBalance = currentBalance + interestOn (currentBalance);
- System.out.println("The balance after 3 years is £" + currentBalance);
- if (currentBalance > SavingsTarget)
- {
- System.out.println("Congratulations, your savings target has been reached");
- }
- }
- public static double interestOn(double balance){
- double interest = balance * 0.05;
- return interest;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement