Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class InterestCalculator2
  4. {
  5. public static void main(String arg[]){
  6. System.out.println("Please enter savings target");
  7. double initialBalance = 10000;
  8. double currentBalance = 0;
  9. System.out.println("The initial balance is £" + initialBalance);
  10. Scanner scan = new Scanner(System.in);
  11. double SavingsTarget = scan.nextDouble();
  12. currentBalance = initialBalance + interestOn (initialBalance);
  13. System.out.println("The balance after 1 year is £" + currentBalance);
  14. if (currentBalance > SavingsTarget)
  15. {
  16. System.out.println("Congratulations, your savings target has been reached");
  17. }
  18. currentBalance = currentBalance + interestOn (currentBalance);
  19. System.out.println("The balance after 2 years is £" + currentBalance);
  20. if (currentBalance > SavingsTarget)
  21. {
  22. System.out.println("Congratulations, your savings target has been reached");
  23. }
  24. currentBalance = currentBalance + interestOn (currentBalance);
  25. System.out.println("The balance after 3 years is £" + currentBalance);
  26. if (currentBalance > SavingsTarget)
  27. {
  28. System.out.println("Congratulations, your savings target has been reached");
  29. }
  30. }
  31. public static double interestOn(double balance){
  32. double interest = balance * 0.05;
  33. return interest;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement