Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. public class BankAccount {
  2.    
  3.     static int balance( int balance, int years) {
  4.         //check for valid input
  5.         if (years > 0 && balance > 0 && balance < 50001) {
  6.             double rate = 0.5;
  7.             if (balance > 1000) {
  8.                 rate = 1.5;
  9.             }
  10.             if (balance > 10000) {
  11.                 rate = 2.5;
  12.             }
  13.             //run calculation
  14.             return (int)Math.round(balance * Math.pow((1+(double)rate/100), years));
  15.         } else {
  16.             //invalid input
  17.             return -1;
  18.         }
  19.     }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement