目录
4.POS类及POSJFrame类:设置GUI窗体,相关组件
1.程序运行截图
2.MemberCard主体及Test测试类
//MemberCard主体
package membercarddemoapp;
import pospackage.POSJFrame;
/**
*
* @author 张阵涛
*/
public class MemberCardDemoApp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
POSJFrame pOSJFrame=new POSJFrame();
pOSJFrame.setVisible(true);
}
}
//Test测试类,可更改卡内金额
package membercarddemoapp;
import membercarddemoapp.cardpackage.MemberCard;
import membercarddemoapp.cardpackage.SuperVIPCard;
import membercarddemoapp.cardpackage.VIPCard;
/**
*
* @author 张阵涛
*/
public class Test {
public static MemberCard membeerCard=new MemberCard("会员卡",500);
public static VIPCard vIPCard=new VIPCard("VIP卡",1000);
public static SuperVIPCard superVIPCard=new SuperVIPCard("超级VIP卡",2000);
}
3.不同卡的类
//Card父类
package membercarddemoapp.cardpackage;
/**
*
* @author 张阵涛
*/
public abstract class Card {
String type;
float amount;
public Card(){
}
public Card(String type){
this.type=type;
}
public Card(String type, float amount) {
this.type = type;
this.amount = amount;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
this.amount = amount;
}
public abstract float shouldPay(float totalPrice);
public boolean consume(float totalPrice){
if(this.amount>=this.shouldPay(totalPrice))
{
this.amount=amount-this.shouldPay(totalPrice);
return true;
}
else
{
return false;
}
}
}
//普通购物卡
package membercarddemoapp.cardpackage;
/**
*
* @author 张阵涛
*/
public class MemberCard extends Card
{
public MemberCard() {
this.type="MenberCard";
}
public MemberCard(String type, float amount) {
super(type, amount);
}
@Override
public float shouldPay(float totalPrice) {
return totalPrice*0.9f;
}
}
//vip购物卡
package membercarddemoapp.cardpackage;
/**
*
* @author 张阵涛
*/
public class VIPCard extends Card{
public VIPCard(){
this.type="VIPCard";
}
public VIPCard(String type, float amount) {
super(type, amount);
}
@Override
public float shouldPay(float totalPrice) {
return totalPrice*0.7f;
}
}