You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
910 B
24 lines
910 B
public class AccountTest {
|
|
public static void main(String[] args) {
|
|
// 创建账户,初始余额 1000 元
|
|
Account account = new Account(1000.0);
|
|
System.out.println("当前账户余额:" + account.getBalance());
|
|
|
|
// 测试取款功能
|
|
System.out.println("\n===== 尝试取款 500 元 =====");
|
|
try {
|
|
account.withdraw(500.0);
|
|
} catch (InsufficientFundsException e) {
|
|
System.out.println("错误:" + e.getMessage());
|
|
System.out.println("当前余额:" + e.getBalance());
|
|
}
|
|
|
|
System.out.println("\n===== 尝试取款 700 元 =====");
|
|
try {
|
|
account.withdraw(700.0);
|
|
} catch (InsufficientFundsException e) {
|
|
System.out.println("错误:" + e.getMessage());
|
|
System.out.println("当前余额:" + e.getBalance());
|
|
}
|
|
}
|
|
}
|