Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Prog6
- {
- public static void main(String[] args)
- {
- Scanner stdIn = new Scanner(System.in);
- String selection;
- char sel;
- double money,balance = 0,wthdrwl,interest = .04;
- do
- {
- System.out.print("D - Deposit\nW - Withdraw\nI - Interest\nB - Balance\nQ - Quit\nSelection: ");
- selection = stdIn.nextLine();
- selection = selection.toUpperCase();
- sel = selection.charAt(0);
- if (sel == 'D')
- {
- do
- {
- System.out.print("Amount of deposit: ");
- money = stdIn.nextDouble();
- if (money < 0)
- {
- System.out.println("You can't deposit a negative amount of money.");
- }
- else
- {
- balance = money + balance;
- System.out.println("Your new balance is: " + balance);
- }
- } while (money < 0);
- }
- if (sel == 'W')
- {
- if (balance <= 0)
- {
- System.out.println("Unable to withdraw. Balance = $0. Returning to menu.");
- }
- if (balance > 0)
- {
- do
- {
- System.out.print("Withdraw Amount: ");
- wthdrwl = stdIn.nextDouble();
- if (wthdrwl > balance || wthdrwl <= 0)
- {
- System.out.println("ERROR: Withdrawl is less than or equal to $0 or exceeds account balance.");
- }
- else
- {
- balance = balance - wthdrwl;
- System.out.println("Your new balance is: " + balance);
- }
- } while (wthdrwl > balance || wthdrwl <= 0);
- }
- }
- if (sel == 'I')
- {
- if (balance <= 0)
- {
- System.out.println("Cannot compute interest on negative or $0 balance.");
- }
- else
- {
- balance = (balance * interest) + balance;
- System.out.println("Interest computed.\nNew balance: " + balance);
- }
- }
- if (sel == 'B')
- {
- System.out.println("Current balance: " + balance);
- }
- } while (sel != 'Q');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement