Advertisement
advictoriam

Untitled

Dec 11th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    This program updates an account balance, according to the table below:
  5.          Balance      Interest Rate    Charge  
  6.      > $100,000.00   2.75 %        $ 0.00
  7.      > $25,000.00    2.00 %        $ 0.00
  8.      > $10,000.00    1.00 %        $ 0.00
  9.     >= $0.00             0.00 %        $ 0.00
  10.      < $0.00             0.00 %       $ 25.00
  11.    and prints out the new balance.
  12. */
  13. public class BankInterest
  14. {
  15.    public static void main(String[] args)
  16.    {
  17.       // Define constants
  18.       final double HI_RATE = 2.75;
  19.       final double MD_RATE = 2.00;
  20.       final double LO_RATE = 1.00;
  21.       final double ZERO_RATE = 0.00;
  22.       final double DEB_CHG = -25.00;
  23.  
  24.       final double HI_LIMIT = 100000.00;
  25.       final double MD_LIMIT = 25000.00;
  26.       final double LO_LIMIT = 10000.00;
  27.       final double ZERO_LIMIT = 0.00;
  28.  
  29.       // Print prompt to enter a current balence
  30.       System.out.print("Enter current balance: ");
  31.  
  32.       // Read balance
  33.       Scanner in = new Scanner(System.in);
  34.       double balance = in.nextDouble();
  35.  
  36.       // Determine interest rate (or charge) based on current balance
  37.       //   to compute new balance
  38.       double newBalance = 0;
  39.       if(balance < ZERO_LIMIT)
  40.          newBalance = balance + DEB_CHG;
  41.       else if(balance >= ZERO_LIMIT && balance <= LO_LIMIT)
  42.          newBalance = balance * (1+ZERO_RATE/100);
  43.       else if(balance > LO_LIMIT && balance <= MD_LIMIT)
  44.          newBalance = balance * (1+LO_RATE/100);
  45.       else if(balance > MD_LIMIT && balance <= HI_LIMIT)
  46.          newBalance = balance * (1+MD_RATE/100);
  47.       else if(balance > HI_LIMIT)
  48.          newBalance = balance * (1+HI_RATE/100);
  49.          
  50.       System.out.printf("%.2f\n", newBalance);
  51.    }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement