24 lines
854 B
Java
24 lines
854 B
Java
package Week8_Lab;
|
|
import java.util.Scanner;
|
|
public class BankDemoTest {
|
|
public static void main(String[] args){
|
|
CheckingAccount c = new CheckingAccount();
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
System.out.print("Enter an amount to deposit: ");
|
|
double amount = sc.nextDouble();
|
|
c.deposit(amount);
|
|
System.out.print("Enter an amount to withdraw: ");
|
|
amount = sc.nextDouble();
|
|
try{
|
|
c.withdraw(amount);
|
|
}catch(InsufficientFundsException e){
|
|
if (e.getAmount() > c.getBalance()){
|
|
System.out.println("Sorry, but your account is short by: $" + (e.getAmount() - c.getBalance()));
|
|
}
|
|
}
|
|
if (amount <= c.getBalance())
|
|
System.out.println("The balance after withdrawal is: $" + (c.getBalance() - amount));
|
|
}
|
|
}
|