用java进行一个银行预约才能存钱的方法
时间: 2023-06-19 21:06:50 浏览: 95
以下是一个简单的银行预约存钱的Java方法:
```java
public class BankAppointment {
private boolean isAppointmentScheduled;
public BankAppointment() {
isAppointmentScheduled = false;
}
public boolean scheduleAppointment() {
if (!isAppointmentScheduled) {
isAppointmentScheduled = true;
return true;
} else {
return false;
}
}
public void depositMoney(double amount) {
if (isAppointmentScheduled) {
System.out.println("Deposit " + amount + " RMB successfully!");
isAppointmentScheduled = false;
} else {
System.out.println("Please schedule an appointment before depositing.");
}
}
}
```
使用方法如下:
```java
BankAppointment bankAppointment = new BankAppointment();
if (bankAppointment.scheduleAppointment()) {
bankAppointment.depositMoney(500.0);
} else {
System.out.println("Appointment already scheduled.");
}
```
在上面的示例中,我们创建了一个BankAppointment类,其中包含两个方法:scheduleAppointment和depositMoney。scheduleAppointment方法用于预约存款,而depositMoney方法用于实际存款。如果在预约存款之前没有预约,那么存款将无法进行。如果预约成功,存款将被执行,而预约状态将被重置为false。
请注意,这只是一个简单的示例,真正的银行系统需要更复杂的逻辑和安全措施。
阅读全文