Advertisement
Guest User

Untitled

a guest
May 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Prog6
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner stdIn = new Scanner(System.in);
  8.         String selection;
  9.         char sel;
  10.         double money,balance = 0,wthdrwl,interest = .04;
  11.         do
  12.         {
  13.             System.out.print("D - Deposit\nW - Withdraw\nI - Interest\nB - Balance\nQ - Quit\nSelection: ");
  14.             selection = stdIn.nextLine();
  15.             selection = selection.toUpperCase();
  16.             sel = selection.charAt(0);
  17.             if (sel == 'D')
  18.             {
  19.                 do
  20.                 {
  21.                     System.out.print("Amount of deposit: ");
  22.                     money = stdIn.nextDouble();
  23.                     if (money < 0)
  24.                     {
  25.                         System.out.println("You can't deposit a negative amount of money.");
  26.                     }
  27.                     else
  28.                     {
  29.                         balance = money + balance;
  30.                         System.out.println("Your new balance is: " + balance);
  31.                     }
  32.                 } while (money < 0);
  33.             }
  34.             if (sel == 'W')
  35.             {
  36.                 if (balance <= 0)
  37.                 {
  38.                     System.out.println("Unable to withdraw. Balance = $0. Returning to menu.");
  39.                 }
  40.                 if (balance > 0)
  41.                 {
  42.                     do
  43.                     {
  44.                         System.out.print("Withdraw Amount: ");
  45.                         wthdrwl = stdIn.nextDouble();
  46.                         if (wthdrwl > balance || wthdrwl <= 0)
  47.                         {
  48.                             System.out.println("ERROR: Withdrawl is less than or equal to $0 or exceeds account balance.");
  49.                         }
  50.                         else
  51.                         {
  52.                             balance = balance - wthdrwl;
  53.                             System.out.println("Your new balance is: " + balance);
  54.                         }
  55.                     } while (wthdrwl > balance || wthdrwl <= 0);
  56.                 }
  57.             }
  58.             if (sel == 'I')
  59.             {
  60.                 if (balance <= 0)
  61.                 {
  62.                     System.out.println("Cannot compute interest on negative or $0 balance.");
  63.                 }
  64.                 else
  65.                 {
  66.                     balance = (balance * interest) + balance;
  67.                     System.out.println("Interest computed.\nNew balance: " + balance);
  68.                 }
  69.             }
  70.             if (sel == 'B')
  71.             {
  72.                 System.out.println("Current balance: " + balance);
  73.             }
  74.         } while (sel != 'Q');
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement