Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BankAccount {
- static int balance( int balance, int years) {
- //check for valid input
- if (years > 0 && balance > 0 && balance < 50001) {
- double rate = 0.5;
- if (balance > 1000) {
- rate = 1.5;
- }
- if (balance > 10000) {
- rate = 2.5;
- }
- //run calculation
- return (int)Math.round(balance * Math.pow((1+(double)rate/100), years));
- } else {
- //invalid input
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement