//账户类
public class Account {
private String type;//账户类型
private String telNo;//电话号码
private int money;//账户余额
private String name;//用户名
private String pwd;//密码
private Taocan taocan;//套餐
private int heji;//合计
public int getHeji() {
return heji;
}
public void setHeji(int heji) {
this.heji = heji;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTelNo() {
return telNo;
}
public void setTelNo(String telNo) {
this.telNo = telNo;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public Taocan getTaocan() {
return taocan;
}
public void setTaocan(Taocan taocan) {
this.taocan = taocan;
}
public Account(String type, String telNo, int money, String name,
String pwd, Taocan taocan) {
super();
this.type = type;
this.telNo = telNo;
this.money = money;
this.name = name;
this.pwd = pwd;
this.taocan = taocan;
}
public Account() {
super();
}
}
//父类
public abstract class Taocan {
private String type;//套餐类型
private int speakTime;// 通话时间;
private int speakTimeLeft;// 剩余的通话时间;
private int price;// 套餐费用
private int flow; // 流量
private int flowLeft;// 流量剩余
private int text;// 短信条数
private int textLeft;// 剩余短信条数
private String recordes;//消费记录
public String getRecordes() {
return recordes;
}
public void setRecordes(String recordes) {
this.recordes = recordes;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getSpeakTime() {
return speakTime;
}
public void setSpeakTime(int speakTime) {
this.speakTime = speakTime;
}
public int getSpeakTimeLeft() {
return speakTimeLeft;
}
public void setSpeakTimeLeft(int speakTimeLeft) {
this.speakTimeLeft = speakTimeLeft;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getFlow() {
return flow;
}
public void setFlow(int flow) {
this.flow = flow;
}
public int getFlowLeft() {
return flowLeft;
}
public void setFlowLeft(int flowLeft) {
this.flowLeft = flowLeft;
}
public int getText() {
return text;
}
public void setText(int text) {
this.text = text;
}
public int getTextLeft() {
return textLeft;
}
public void setTextLeft(int textLeft) {
this.textLeft = textLeft;
}
public Taocan(int speakTime, int price, int flow, int text) {
this.speakTime = speakTime;
this.price = price;
this.flow = flow;
this.text = text;
}
public Taocan() {
super();
}
//打印信息
public abstract void printInfo();
//消费
public void consume(String TelNo){
}
}
//子类
import com.pt.test.Test;
public class NetTaocan extends Taocan{
//网虫套餐
public NetTaocan(){
super.setSpeakTime(0);// 通话时间
super.setPrice(68);//套餐费用
super.setFlow(1024*5);//流量
super.setText(0);//短信
super.setType(“网虫套餐”);
}
@Override
public void printInfo() {
System.out.println(“网虫套餐: \r\n” + “上网流量:5GB\r\n” + “月资费:68元”);
}
public void consume(String TelNo){
int choise = (int)(Math.random()*2);
switch (choise) {
case 1:
useFlow(TelNo);
break;
default:
break;
}
}
private void useFlow(String telNo) {
int money=0;//当前消费金额
System.out.println(“使用流量3000”);
if(this.getRecordes()!=null){
this.setRecordes(this.getRecordes()+” “+”使用流量3000”);
}else{
System.out.println(“使用流量1200”);
}
//剩余流量
if(this.getFlow()-3000>=0){
this.setFlow(this.getFlow()-3000);
System.out.println(this.getFlow());
}else{
money=(1200-this.getFlow())*1;
this.setFlow(0);
for (int i = 0; i