Initial commit
This commit is contained in:
23
实验报告模板/实验报告6/p14/BusCard.java
Normal file
23
实验报告模板/实验报告6/p14/BusCard.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.p14;
|
||||
|
||||
public class BusCard {
|
||||
private float balance;
|
||||
public BusCard() {
|
||||
balance=0;
|
||||
}
|
||||
public float queryBalance() {
|
||||
return balance;
|
||||
}
|
||||
public void charge(float money) {
|
||||
balance=balance+money;
|
||||
}
|
||||
public void swipe(float money) throws CardException{
|
||||
if(balance<money) {
|
||||
CardException ex=new CardException("余额不足,无法刷卡,请尽快充值!");
|
||||
throw ex;
|
||||
}else {
|
||||
balance=balance-money;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user