用Java编写银行账户存取款业务 , 急求?。?/h2>public class Account {
protected String accId;
protected String name;
protected double money;
public Account (String accId,String name){
this(accId,name,0);
}
public Account (String accId,String name,double money){
this.accId = accId;
this.name = name;
this.money = money;
}
public void saveMoney(double money){
if(money = 0){
System.out.println("存款金额必须大于0");
}
this.money += money;
System.out.println("存款成功");
}
public double getMoney(double money){
if(money = 0){
System.out.println("取款金额必须大于0");
return 0;
}
【java银行销户代码 银行卡java程序】if(this.money = money){
System.out.println("余额不足,无法取款");
return 0;
}
this.money -= money;
System.out.println("取款成功");
return money;
}
public double getBalance(){
return this.money;
}
protected double getOverdraft(){
return 0;
}
// 实现了equals方法,list比较时才能正确
@Override
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(this == obj){
return true;
}
if(obj instanceof Account){
return this.accId.equals(((Account)obj).accId);
}
return false;
}
@Override
public String toString() {
return "账户=" + accId + ",名字=" + name + ",余额=" + money;
}
}
public class Bank {
// Account实现了equals方法,list查找时才能正确
private ListAccount usersAccounts;
public Bank() {
usersAccounts = new ArrayListAccount();
}
public void addAccount(Account account) {
if (usersAccounts.contains(account)) {
System.out.println("添加失败,不能添加同样的账户");
return;
}
usersAccounts.add(account);
}
public boolean delAccount(Account account) {
return usersAccounts.remove(account);
}
public boolean delAccount(String accId) {
return delAccount(new Account(accId, null));
}
public boolean existAccount(Account account) {
return usersAccounts.contains(account);
}
public boolean existAccount(String accId) {
return existAccount(new Account(accId, null));
}
public Account getAccount(String accId){
return usersAccounts.get(usersAccounts.indexOf(new Account(accId, null)));
}
public double getAllMoney() {
// 不考虑是否溢出 , 只是把所有用户余额相加
double result = 0;
for (Account account : usersAccounts) {
result += account.getBalance();
}
return result;
}
public double getAllOverdraft() {
// 不考虑是否溢出
double result = 0;
for (Account account : usersAccounts) {
result += account.getOverdraft();
}
return result;
}
public int getAccountNum() {
return usersAccounts.size();
}
public int getCreditAccountNum() {
int num = 0;
for (Account account : usersAccounts) {
// instanceof 性能没有简单的方法快 。
if (account instanceof CreditAccount) {
num++;
}
}
return num;
}
public int getSavingAccountNum() {
int num = 0;
for (Account account : usersAccounts) {
if (account instanceof SavingAccount) {
num++;
}
}
return num;
}
public ListAccount getAllAccount() {
return usersAccounts;
}
}
public class CreditAccount extends Account{
private double overdraft;
public CreditAccount(String accId,String name){
super(accId, name);
推荐阅读
- vpc虚拟机绿色正式版,虚拟机最新版
- 免费版erp系统免,免费erp系统
- 苹果手机pdf文件怎么打开,pdf用苹果手机怎么打开
- 微信视频号卖产品违法吗,视频号售卖
- mysql任意值怎么表示 mysql怎么定义规则
- 鸿蒙系统电量低就卡,鸿蒙系统用电量快
- 以前的养成猫咪游戏下载,很老的一款猫咪养成游戏
- 赛车手机游戏推荐低配车,赛车游戏手游推荐
- c语言函数递归求阶乘 c语言递归求n的阶乘相加