当前位置:首页 » 编程语言 » JavaCard

JavaCard

发布时间: 2024-09-15 19:46:39

java定义一个银行卡类(BankCard)以及派生类ForeignCard,LimitedCard,成员包括姓名,卡

abstract class BankCard {

protected String name;
protected String cardNo;
protected double money;

public BankCard(String name, String cardNo, double money) {
super();
this.name = name;
this.cardNo = cardNo;
this.money = money;
}

public String getName() {
return name;
}
public String getCardNo() {
return cardNo;
}
public double getMoney() {
return money;
}

public abstract void unputMoney(int someMoney);

public void putMoney(int someMoney) {
this.money += someMoney;
}
}

class ForeignCard extends BankCard {

public ForeignCard(String name, String cardNo, double money) {
super(name, cardNo, money);
}

@Override
public void unputMoney(int someMoney) {
double left = getMoney() - someMoney * 1.01;
if(left >= 0) {
super.money = left;
} else {
throw new RuntimeException("余额不足");
}
}
}

class LimitedCard extends BankCard {

public LimitedCard(String name, String cardNo, double money) {
super(name, cardNo, money);
}

@Override
public void unputMoney(int someMoney) {
if(someMoney > 1000) {
throw new RuntimeException("取款不能超过1000");
}
if(getMoney() < someMoney) {
throw new RuntimeException("余额不足");
}
super.money -= someMoney;
}
}

热点内容
钟算算法 发布:2024-11-25 02:41:45 浏览:532
php微信开源商城 发布:2024-11-25 02:23:31 浏览:28
哈哈脚本官网 发布:2024-11-25 02:19:47 浏览:742
服务器屏锁后怎么登录 发布:2024-11-25 02:10:45 浏览:222
四驱汉兰达买哪个配置性价比高 发布:2024-11-25 02:04:52 浏览:684
pythonsocket阻塞非阻塞 发布:2024-11-25 02:04:41 浏览:490
中温压缩机 发布:2024-11-25 01:59:54 浏览:278
小米怎么查看云相册密码是什么 发布:2024-11-25 01:46:38 浏览:686
不同的语言编译原理 发布:2024-11-25 01:30:37 浏览:315
c编译成c 发布:2024-11-25 01:29:12 浏览:105