设计一个账户类account,包括id,balance,rate,date:Calendar,withdraw,deposit
时间: 2023-06-17 12:03:32 浏览: 148
设计一个银行账户类。其中包括以下内容,并用字符界面模拟存款和取款过程。
5星 · 资源好评率100%
好的,以下是一个简单的Java代码实现:
```
import java.util.Calendar;
public class Account {
private String id;
private double balance;
private double rate;
private Calendar date;
public Account(String id, double balance, double rate, Calendar date) {
this.id = id;
this.balance = balance;
this.rate = rate;
this.date = date;
}
public String getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getRate() {
return rate;
}
public Calendar getDate() {
return date;
}
public void withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient funds");
} else {
balance -= amount;
}
}
public void deposit(double amount) {
balance += amount;
}
}
```
其中,id是账户ID,balance是账户余额,rate是利率,date是开户日期,withdraw方法用于取款,deposit方法用于存款。
阅读全文