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.
45 lines
1.7 KiB
45 lines
1.7 KiB
/**
|
|
* 测试类 - 用于测试 BankAccount 类的功能
|
|
*/
|
|
void main() {
|
|
// 可以通过命令行参数自定义账户信息
|
|
String accountNumber = "62220219900101";
|
|
String ownerName = "张三";
|
|
|
|
// 1. 创建银行账户(必须提供账户号和户主姓名)
|
|
var account = new BankAccount(accountNumber, ownerName);
|
|
|
|
// 2. 显示初始信息
|
|
System.out.println("=== 账户初始化 ===");
|
|
System.out.println("账户号:" + account.getAccountNumber());
|
|
System.out.println("户主姓名:" + account.getOwnerName());
|
|
System.out.println("初始余额:" + account.getBalance() + "元\n");
|
|
|
|
// 3. 测试存款操作
|
|
System.out.println("=== 测试存款 ===");
|
|
account.deposit(5000); // 成功
|
|
account.deposit(-100); // 失败:金额为负数
|
|
System.out.println();
|
|
|
|
// 4. 测试取款操作
|
|
System.out.println("=== 测试取款 ===");
|
|
account.withdraw(2000); // 成功
|
|
account.withdraw(5000); // 失败:余额不足
|
|
account.withdraw(-500); // 失败:金额为负数
|
|
System.out.println();
|
|
|
|
// 5. 查询当前余额
|
|
System.out.println("=== 查询余额 ===");
|
|
System.out.println("当前余额:" + account.getBalance() + "元\n");
|
|
|
|
// 6. 测试修改户主姓名
|
|
System.out.println("=== 修改户主姓名 ===");
|
|
account.setOwnerName("李四");
|
|
System.out.println();
|
|
|
|
// 7. 显示最终信息
|
|
System.out.println("=== 最终账户信息 ===");
|
|
System.out.println("账户号:" + account.getAccountNumber());
|
|
System.out.println("户主姓名:" + account.getOwnerName());
|
|
System.out.println("当前余额:" + account.getBalance() + "元");
|
|
}
|
|
|