當前位置:首頁 » 編程語言 » 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;
}
}

熱點內容
地鐵加密線是什麼意思 發布:2025-04-04 12:32:00 瀏覽:118
linux下載解壓 發布:2025-04-04 12:23:45 瀏覽:789
怎麼在伺服器里設材質包 發布:2025-04-04 12:10:08 瀏覽:630
php學習路線 發布:2025-04-04 12:05:13 瀏覽:754
壓縮文件視頻 發布:2025-04-04 12:00:48 瀏覽:319
17php 發布:2025-04-04 11:54:33 瀏覽:213
仿鏈家源碼 發布:2025-04-04 11:48:46 瀏覽:423
籃球訓練視頻文字腳本 發布:2025-04-04 11:47:18 瀏覽:839
兩麥分離演算法 發布:2025-04-04 11:23:45 瀏覽:431
換一個瀏覽器ftp打不開 發布:2025-04-04 11:23:44 瀏覽:184