嗖嗖移动大厅项目



import sun.nio.cs.UTF_32;

import java.io.*;
import java.util.*;

//工具类
public class CardUtil {
    Scene scene = new Scene ( "问候客户,谁知如此难缠打电话90分钟", "通话", 90 );
    Scene scene1 = new Scene ( "通知朋友手机号换号发短信50条", "发短信", 50 );
    Scene scene2 = new Scene ( "参与环境保护实施方案问卷调查发短信5条", "短信", 5 );
    Scene scene3 = new Scene ( "和朋友用微信视频聊天,使用流量1G", "流量", 1024 );
    Scene scene4 = new Scene ( "询问妈妈身体状况,本地通话30分钟", "通话", 30 );
    Scene scene5 = new Scene ( "和朋友打游戏花费2G流量", "流量", 1024 * 2 );
    public CardUtil() {
    }

    Scanner input = new Scanner ( System.in );//向控制台输出
    private static Map<String, MoblieCard> cards = new HashMap<> ();//存放手机号及内容
    List<String> uui = new ArrayList ();
    static Map<String, List<ConsumInf>> map = new HashMap<> ();//存放手机号及消费记录
    //创建新卡
    public void initScene() {//注册新卡
        MoblieCard h1 = new MoblieCard ();//创建对象
        StringBuffer i = new StringBuffer ( "139" );//开始创建一个139开头
        System.out.println ( "******可选的号码有:********" );
        Random p = new Random ();//随机数对象
        int xy = 0;//标记
        for (int x = 0; x < 9; x++) {//外层循环循环一次一个11位的数
            String po = null;

            for (int j = 0; j < 8; j++) {
                int h = p.nextInt ( 10 );//每次运行创建一个0-9的数
                if ((i.append ( h ).toString ().length ()) == 11) {//拼接判断够了没有
                    po = i.toString ();//整体转换为字符串
                    i = new StringBuffer ( "139" );//再次创建一个对象
                }
            }
            System.out.print ( "    " + (xy + 1) + "、" + po );//输出每次产生的随机数
            uui.add ( po );//将每次产生的随机数暂时存储到数组中。
            xy += 1;
            if (xy % 3 == 0) {//产生3个就换行
                System.out.println ();
            }//换行的作用
        }//产生随机数并放到集合中
        int x;//号码的数减一的下标
        boolean lk;

        do {
            System.out.println ( "请选择卡号(输入1-9的序号):" );
            lk = true;//标记
            x = input.nextInt ();
            if (x < 1 || x > 9) {
                try {
                    lk = false;//说明只要能执行到这里就让他继续循环

                } catch (Exception e) {
                    System.out.println ( "输入的号码错误。" );
                }
            }
        } while (!lk);
        if (cards.containsKey ( uui.get ( x - 1 ) )) {//判断号码是否重复
            System.out.println ( "这个号码重复了" );
            System.out.println ( "请重新注册" );
            return;
        }
        System.out.println ( "请输入姓名:" );
        h1.setUserName ( input.next () );//存储到当前对象的里面了
        System.out.println ( "请输入密码:" );

        h1.setRealSMSCount ( input.nextInt () );//存储到当前对象的里面了
        System.out.println ( "1、话唠套餐  2、网虫套餐   3、超人套餐" );
        int a=input.nextInt () ;
        System.out.println ( "请输入预存话费金额:" );
        h1.setMoney ( input.nextDouble () );

        h1.setReadIFlow ( uui.get ( x - 1 ) );


        switch (a) {//new套餐对象
            case 1:
                h1.setTaocan ( new TalkPakage () );
                break;
            case 2:
                h1.setTaocan ( new NetPakage () );
                break;
            case 3:
                h1.setTaocan ( new SuperPakage () );
                break;
        }
        while (h1.getMoney () < 78) {
            System.out.print ( "您预存的话费金额不足以支付本月固定套餐资费,请重新选择重新:" );
            h1.setMoney ( input.nextDouble () );//存储到当前对象的里面了

        }


        System.out.print ( "注册成功!卡号为" + h1.getReadIFlow () + " 用户名:" + h1.getUserName () + "密码是:" + h1.getRealSMSCount () + "    " );
        h1.getTaocan ().showInfo ();

        System.out.println ( "扣除本月话费为" + ( h1.getMoney () - h1.getTaocan ().getPric1 () ) );
        cards.put ( uui.get ( x - 1 ), h1 );//放到集合里

        uui.clear ();//清空集合
    }//新卡完成
    //二级菜单
    public void chargeMoney() {//用户登录
        System.out.println ( "请输入账号:" );
        String number = input.next ();
        System.out.println ( "请输入密码:" );
        double money = input.nextDouble ();

        if (cards.containsKey ( number )) {//判断是否存在
            MoblieCard g = (MoblieCard) cards.get ( number );
            if (g.getRealSMSCount () == money) {//获取value对比
                System.out.println ( "欢迎用户:" + g.getUserName () + "使用菜单:" );
                do {
                    System.out.println ( "**********搜搜移动用户菜单**********" );
                    System.out.println ( "1、本月账单查询" );
                    System.out.println ( "2、套餐余量查询" );
                    System.out.println ( "3、打印消费账单" );
                    System.out.println ( "4、套餐变更" );
                    System.out.println ( "5、办理退网" );
                    System.out.println ( "请选择(输入1-5选择功能,其他键返回上一级)" );
                    int x = input.nextInt ();

                    switch (x) {
                        case 1:
                            benyuezhangdan ( number );//本月账单查询
                            break;
                        case 2:
                            yuliang ( number );//套餐余量查询

                            break;
                        case 3:
                            dayin (  );//打印

                            break;
                        case 4:
                            biangeng ( number );//变更套餐
                            break;
                        case 5:
                            shanchu ( number );//删除
                            break;
                        default:
                            System.out.println ( "拜拜" );
                            return;
                    }

                } while (true);
            }
        }

    }
    //进入场景
    public void changjin() {

        System.out.print ( "请输入手机号" );
        String number = input.next ();
        SerivicePakage serivicePakage = cards.get (number).getTaocan ();//当前账号的套餐
        MoblieCard moblieCard = cards.get ( number );
        Random random = new Random ();
        int yi=0;//记录本场消费多少钱;
        while (true) {

            int e = random.nextInt ( 6 );
            switch (e) {
                case 0:
                    if (serivicePakage instanceof tonghua) {
                        System.out.println ( scene.getData () );
                        tonghua tonghua = (tonghua) serivicePakage;
                        //传过去一个使用数量和当前使用的卡,记录在卡中的消费内容
                        try {
                            yi = tonghua.call ( scene.getNo (), moblieCard );
                        } catch (Exception e1) {
                            e1.printStackTrace ();
                        }
                        //创建一条消费记录
                        xiaofie ( number, new ConsumInf ( scene.getData (), scene.getType (), yi ) );
                    }else {
                        continue;
                    }
                    break;
                case 1:
                    if (serivicePakage instanceof duanxin) {
                        System.out.println ( scene1.getData () );
                        duanxin duanxin=(duanxin)serivicePakage;
                        try {
                            yi = duanxin.dainxin ( scene1.getNo (), moblieCard );
                        } catch (Exception e1) {
                            e1.printStackTrace ();
                        }
                        //创建一条消费记录
                        xiaofie ( number, new ConsumInf ( scene1.getData (), scene1.getType (), yi ) );
                    } else {
                        continue;
                    }
                    break;
                case 2:
                    if (serivicePakage instanceof duanxin) {
                        System.out.println ( scene2.getData () );
                        duanxin duanxin=(duanxin)serivicePakage;
                        try {
                            yi = duanxin.dainxin ( scene2.getNo (), moblieCard );
                        } catch (Exception e1) {
                            e1.printStackTrace ();
                        }
                        //创建一条消费记录
                        xiaofie ( number, new ConsumInf ( scene2.getData (), scene2.getType (), yi ) );
                    }else {
                        continue;
                    }
                    break;
                case 3:
                    if (serivicePakage instanceof liuliang) {
                        System.out.println ( scene3.getData () );
                        liuliang liuliang= (liuliang) serivicePakage;
                        try {
                            yi=liuliang.liuliang (  scene3.getNo (), moblieCard);
                        } catch (Exception e1) {
                            e1.printStackTrace ();
                        }
                        xiaofie ( number, new ConsumInf ( scene3.getData (), scene3.getType (), yi ) );
                    }else {
                        continue;
                    }
                    break;

                case 4:

                    if (serivicePakage instanceof tonghua) {
                        System.out.println ( scene4.getData () );
                        tonghua tonghua = (tonghua) serivicePakage;
                        //传过去一个使用数量和当前使用的卡,记录在卡中的消费内容
                        try {
                            yi = tonghua.call ( scene4.getNo (), moblieCard );
                        } catch (Exception e1) {
                            e1.printStackTrace ();
                        }
                        //创建一条消费记录
                        xiaofie ( number, new ConsumInf ( scene4.getData (), scene4.getType (), yi ) );
                    }else {
                        continue;
                    }
                    break;
                case 5:
                    if (serivicePakage instanceof liuliang) {
                        System.out.println ( scene5.getData () );
                        liuliang liuliang= (liuliang) serivicePakage;

                        try {
                            yi=liuliang.liuliang (  scene5.getNo (), moblieCard);
                        } catch (Exception e1) {
                            e1.printStackTrace ();
                        }

                        xiaofie ( number, new ConsumInf ( scene5.getData (), scene5.getType (), yi ) );
                    }else {
                        continue;
                    }
                    break;
            }
            break;
        }
    }
    //创建一条消费记录
    public void xiaofie(String X, ConsumInf Y) {//传过来一个账号,一个消费记录,金额
        if (map.containsKey ( X )) {//说明有消费记录在基础上添加就可以
            map.get ( X ).add ( Y );
        } else {//说明没有记录需要给他创建个集合
            List<ConsumInf> list = new ArrayList ();
            list.add ( Y );//存进一条记录
            map.put ( X, list );
        }

    }
    //打印消费记录
    private void dayin() {
        System.out.print("请输入要打印的消费账单号码:");

        String name=input.next ();
        FileWriter writer= null;
        BufferedWriter writer1=null;
        try {

            if (map.containsKey ( name )){
                writer = new FileWriter ( "C:\\消费账单.txt",true );
                writer1 = new BufferedWriter ( writer );
                String name1="***********"+name+"消费记录"+"***********";
                writer1.write (name1 );
                writer1.newLine ();
                String jj="序号\t类型\t数据(通话条/上网(MB)/短信(条))";
                writer1.write ( jj );
                writer1.newLine ();
                ArrayList<ConsumInf> consumInfs= (ArrayList<ConsumInf>) map.get ( name );
                for (int i = 0; i <consumInfs.size () ; i++) {
                    String ss=(i+1)+"\t"+consumInfs.get ( i ).getType ()+"\t"+consumInfs.get ( i ).getQuantity ();

                    writer1.write (ss);
                    writer1.newLine ();
                    writer1.flush ();
                }
                System.out.println ("打印成功。");
            }else {
                System.out.println ("没有消费记录不能打印");
            }
        } catch (IOException e) {
            e.printStackTrace ();
        }finally {
            if (writer1 != null) {
                try {
                    writer1.close ();
                } catch (IOException e) {
                    e.printStackTrace ();
                }
            }
        }

    }
    //删除方法
    private void shanchu(String number) {
        System.out.println ( "卡号:" + number + "正在删除。。" );
        if (cards.containsKey ( number )) {
            cards.remove ( number );//通过key删除
            System.out.println ( "卡号删除成功" );
        } else {
            System.out.println ( "找不到卡号" );
            return;
        }//删除卡号及对像
        if (map.containsKey ( number )) {
            map.remove ( number );
            System.out.println ( "消费记录删除成功" );
        } else {
            System.out.println ( "没有消费记录" );
        }//删除消费记录
        System.out.println ( "退网成功。" );

    }//完成
    //充值方法
    public void chongzhi() {//充值方法
        System.out.println ( "欢迎使用充值系统:" );
        System.out.println ( "请输入你要重值得卡号:" );
        String a = input.next ();
        if (cards.containsKey ( a )) {
            System.out.print ( "请输入要冲的金额(最多1000、最少50元):" );
            double y = input.nextDouble ();
            if (y > 100 | y < 50) {
                System.out.println ( "请安说明重置:" );
                try {
                    throw new Exception ( "输入错误" );
                } catch (Exception e) {
                    System.out.println ( "请重新重置" );
                }
            }
            cards.get ( a ).setMoney ( cards.get ( a ).getMoney () + y );
            System.out.println ( "充值成功" );
            System.out.println ( "当前余额为:" + cards.get ( a ).getMoney () );
        } else {
            System.out.println ( "号码输入错误" );
        }
    }//搞定
    //更改套餐
    public void biangeng(String in) {
        System.out.println ( "**********套餐变更**********" );
        System.out.print ( "1、话唠套餐  2、网虫套餐   3、超人套餐  请选择:" );
        int j = input.nextInt ();
        if ((cards.get ( in ).getMoney () - cards.get ( in ).getTaocan ().getPric1 ()) < 78) {
            System.out.println ( "对不起您余额不足支付本月月租,请充值在更换。" );
            return;
        }else
        switch (j) {
            case 1:
                if (cards.get ( in ).getTaocan () instanceof TalkPakage) {
                    System.out.println ( "对不起该用户已是改套餐。" );
                    return;
                } else {
                    cards.get ( in ).setTaocan ( new TalkPakage () );
                }
                break;
            case 2:
                if (cards.get ( in ).getTaocan () instanceof NetPakage) {
                    System.out.println ( "对不起该用户已是改套餐。" );
                    return;
                } else {
                    cards.get ( in ).setTaocan ( new NetPakage () );
                }
                break;
            case 3:
                if (cards.get ( in ).getTaocan () instanceof SuperPakage) {
                    System.out.println ( "对不起该用户已是改套餐。" );
                    return;
                } else {
                    cards.get ( in ).setTaocan ( new SuperPakage () );
                }
                break;
            default:
                System.out.println ( "出现未知异常结束,可能此号码为空" );
                return;
        }



            MoblieCard moblieCard = cards.get ( in );
            ArrayList<ConsumInf> c = (ArrayList<ConsumInf>) map.get ( in );
            map.remove ( c );
            moblieCard.setRealTalkTime ( 0 );
            moblieCard.setConsumAmount ( 0 );
            moblieCard.setRealSMSCount ( 0 );
            moblieCard.setNote ( 0 );
            //本剩余余额减去本月产生的钱,再扣除下个月的套餐资费
            moblieCard.setMoney ( cards.get ( in ).getMoney ()  - cards.get ( in ).getTaocan ().getPric1 () );
            moblieCard.setActual_flow ( 0 );
            System.out.println ("更换套餐成功套餐为"+cards.get ( in ).getTaocan ().getName());
            //清空数据

    }//搞定
    //本月账单
    public void benyuezhangdan(String Zhanghao) {//本月账单传过来一个key
        if (cards.containsKey ( Zhanghao )) {//判断是否在排除了被删除的因数
            System.out.println ( "您的卡号:" + Zhanghao + ",当月账单:" );
            MoblieCard k = cards.get ( Zhanghao );
            double i = k.getTaocan ().getPric1 ();//获取当前套的资费
            System.out.println ( "套餐资费是:" + i + "元" );//价格方法

            System.out.println ( "合计是:" + (i + k.getConsumAmount ()) + "元" );
            System.out.println ("未扣除本月余额是:"+((int)k.getMoney ())+ "元");
            System.out.println ("扣除本月余额是:"+((int)(k.getMoney ()-i))+ "元");
        } else {
            System.out.println ( "此张卡刚刚被删除了。" );
        }


    }//完成
    //本月剩余套餐内容
    public void yuliang(String number) {//剩余的套餐

        int s = 0;//计算流量
        int ss = 0;//计算短信余量
        int sss = 0;//计算剩余分钟
        MoblieCard l = cards.get ( number );
        SerivicePakage i = l.getTaocan ();
        if (cards.containsKey ( number )) {//集合中找卡号
            System.out.println ( "您的卡号是:" + number + ",套餐剩余:" );
            //计算就使用当前套餐的余量减去实际使用的。
            if (i instanceof SuperPakage) {
                SuperPakage ii = (SuperPakage) i;
                s = ii.getPrice () - l.getActual_flow ();

                ss = ii.getSmsCount () - l.getNote ();

                sss = ii.getTalkTime () - l.getRealTalkTime ();
            }
            if (i instanceof NetPakage) {
                NetPakage ii = (NetPakage) i;
                s = ii.getPrice () - l.getActual_flow ();

                ss = ii.getSmsCount () - l.getNote ();

                sss = ii.getTalkTime () - l.getRealTalkTime ();
            }
            if (i instanceof TalkPakage) {
                TalkPakage ii = (TalkPakage) i;
                s = ii.getPrice () - l.getActual_flow ();

                ss = ii.getSmsCount () - l.getNote ();

                sss = ii.getTalkTime () - l.getRealTalkTime ();
            }


        } else {
            System.out.println ( "卡号不存在。可能被删除" );
            return;
        }
        int a = (sss < 0) ? 0 : sss;
        int a1 = (ss < 0) ? 0 : ss;
        int a2 = (s < 0) ? 0 : (s / 1024);
        System.out.println ( "通话时长:" + a + "分钟" );
        System.out.println ( "短信条数:" + a1 + "条" );
        System.out.println ( "流量剩余:" + a2 + "GB" );


    }//完成

    //三个数据初始化完成
    public void CardUtil(boolean y) {//初始化数据
        if (!y) {
            System.out.println ( "没有初始化" );
            return;
        }
        //创建上三个手机号及内容按照用户名、手机号、密码、套餐类型、消费金额、钱、实际通话、实际上网、实际短信
        MoblieCard card1 = new MoblieCard ( "小王", "13979387057", 123214124,
                new TalkPakage (), 0, 212, 30, 0, 0 );// 话痨套餐
        MoblieCard card2 = new MoblieCard ( "小花", "13979387058", 123214,
                new TalkPakage (), 0, 212, 0, 30, 0 );// 网虫套餐
        MoblieCard card3 = new MoblieCard ( "小王", "13979387059", 124124,
                new TalkPakage (), 0, 212, 0, 0, 30 );// 超人套餐
        //把创建好的手机号存进去

        cards.put ( "13979387057", card1 );
        cards.put ( "13979387058", card2 );
        cards.put ( "13979387059", card3 );
        ConsumInf j = new ConsumInf ( "13979387057", "通话时长", 30 );//有参构造分别可以是通话时长、短信条数、流量
        ConsumInf j1 = new ConsumInf ( "13979387058", "上网", 30 );
        ConsumInf j2 = new ConsumInf ( "13979387059", "短信条数", 30 );
        //因为消费记录不仅仅是一条所以要用集合存放起来,一个账号的消费记录就用一个集合存
        List<ConsumInf> l = new ArrayList ();
        l.add ( j );
        map.put ( j.getNumber (), l );
        List<ConsumInf> l1 = new ArrayList ();
        l1.add ( j1 );
        map.put ( j1.getNumber (), l1 );
        List<ConsumInf> l2 = new ArrayList ();
        l2.add ( j2 );
        map.put ( j2.getNumber (), l2 );

    }//完成
    //套餐资费
    public void xiangdan() {
        BufferedReader reader=null;
        try {
            reader=new BufferedReader ( new FileReader("C:\\资费说明.txt"));
            String CV;
            while ((CV=reader.readLine ())!=null){
                System.out.println (CV);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace ();
        } catch (IOException e) {
            e.printStackTrace ();
        } finally {
            if (reader!=null){
                try {
                    reader.close ();
                } catch (IOException e) {
                    e.printStackTrace ();
                }
            }
        }
    }
}

```java
//短信的接口
public interface duanxin {
    public int  dainxin(int count, MoblieCard card) throws Exception;
}
public interface liuliang {
    public int liuliang(int count, MoblieCard card) throws Exception;
}
public interface tonghua {
    public int call (int in,MoblieCard on) throws Exception;
}
import java.util.Scanner;

//搜搜移动卡
public class MoblieCard  {
    private String userName;
    private String readIFlow;//卡号
    private int realSMSCount;//密码
    private SerivicePakage taocan;//套餐类型
    private double consumAmount;//消费金额
    private double money;//钱
    private int realTalkTime;//实际用通话时长
    private int  note;//实际使用短信
    private int actual_flow;//实际流量

    //创建一个移动卡的有参构造
    public MoblieCard(String userName, String readIFlow, int realSMSCount, SerivicePakage taocan, double consumAmount, double money, int realTalkTime, int note, int actual_flow) {
        this.userName = userName;
        this.readIFlow = readIFlow;
        this.realSMSCount = realSMSCount;
        this.taocan = taocan;
        this.consumAmount = consumAmount;
        this.money = money;
        this.realTalkTime = realTalkTime;
        this.note = note;
        this.actual_flow = actual_flow;
    }

    public int getNote() {
        return note;
    }

    public void setNote(int note) {
        this.note = note;
    }

    public int getActual_flow() {
        return actual_flow;
    }

    public void setActual_flow(int actual_flow) {
        this.actual_flow = actual_flow;
    }


    public MoblieCard() {
    }



    public SerivicePakage getTaocan() {
        return taocan;
    }

    public void setTaocan(SerivicePakage taocan) {
        this.taocan = taocan;
    }





    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }



    public double getConsumAmount() {
        return consumAmount;
    }

    public void setConsumAmount(double consumAmount) {
        this.consumAmount = consumAmount;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public int getRealTalkTime() {
        return realTalkTime;
    }

    public void setRealTalkTime(int realTalkTime) {
        this.realTalkTime = realTalkTime;
    }

    public int getRealSMSCount() {
        return realSMSCount;
    }

    public void setRealSMSCount(int realSMSCount) {
        this.realSMSCount = realSMSCount;
    }

    public String getReadIFlow() {
        return readIFlow;
    }

    public void setReadIFlow(String readIFlow) {
        this.readIFlow = readIFlow;
    }



    public static void main(String []args){
        showMeg();
    }
    public static void showMeg()  {//开始菜单
        CardUtil j=new CardUtil(); //工具类对象
        j. CardUtil(true);//是否创建用户
        System.out.println("************欢迎使用搜搜移动大厅***************");
        Scanner input = new Scanner(System.in);
        do{
            System.out.println("1、用户登录    2、用户注册    3、使用搜搜    4、话费充值    5、资费说明     6退出系统");
            System.out.print("请选择:");
            int a = input.nextInt();

            switch (a) {
                case 1://用户登录
                    j.chargeMoney();

                    break;
                case 2://用户注册
                    j.initScene();
                    break;
                case 3://使用场景
                    j.changjin ();
                    break;
                case 4:
                    j.chongzhi ();//完成
                    break;
                case 5:
                    j.xiangdan();
                    break;
                case 6:
                    System.out.println ("退出程序。");
                    return;

            }
        }while(true);

    }
    }
    package sosoyidongyewudating;
//网虫套餐
public class NetPakage extends SerivicePakage implements liuliang{

    private int price=3*1024;//流量
    private String tpye="网虫套餐";
    private int talkTime;//通话分钟
    private int smsCount;//短信

    @Override
    public String getName() {
        return this.tpye;
    }

    public String getTpye() {
        return tpye;
    }

    public void setTpye(String tpye) {
        this.tpye = tpye;
    }

    public int getPrice() {
        return price;
    }

    @Override
    public void setPrice(int price) {
        this.price = price;
    }



    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }



    @Override
    public void showInfo() {
        System.out.println("当前套餐是"+this.tpye+",通话时长是"+this.talkTime+"分钟," +
                "短信是:"+this.smsCount+"条,流量是:"+this.price/1024+"G");
    }

    @Override
    public double getPric1() {
        return 68;
    }


//实现消费方法
    @Override
    public int liuliang(int count, MoblieCard card) {
        int X=count;
        for (int i = 0; i <count ; i++) {
            //当前的流量减去实际消费的流量,看看他有流量没有有了
            if ((this.price -card.getActual_flow ())>=1){
                card.setActual_flow ( card.getActual_flow ()+1 );//如果有的话给他在实际用量的基础上加1.
            }else if(card.getMoney ()-card.getTaocan ().getPric1 ()>=0.1){//说明他至少也能通话一分钟
                //实际用量的基础上加1.
                card.setActual_flow ( card.getActual_flow ()+1 );
                //给他的实际消费加上0.1,因为他套餐的时长用完了,所以要扣钱
                card.setMoney ( card.getMoney ()-0.1 );
                //消费金额加0.1
                card.setConsumAmount ( card.getConsumAmount ()+0.1 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;
                try {
                    throw new Exception ( "本次上网"+i+"MB余额不足" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;

            }

        }
        return X;
    }
}

//话唠套餐
public class TalkPakage extends SerivicePakage implements duanxin, tonghua {
    private int talkTime = 500;//通话时长
    private int smsCount = 30;//短信
    private String tpye = "话唠套餐";
    private int price;

    @Override
    public String getName() {
        return this.tpye;
    }


    @Override
    public double getPric1() {
        return 58;
    }

    public void setTpye(String tpye) {
        this.tpye = tpye;
    }


    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }


    @Override
    public void showInfo() {
        System.out.println ( "当前套餐是" + this.tpye + ",通话时长是" + this.talkTime + "分钟," +
                "短信是:" + this.smsCount + "条,流量是:" + this.price + "G" );
    }

    //短信
    @Override
    public int dainxin(int count, MoblieCard card)  {
        int X = count;
        for (int i = 0; i < count; i++) {
            //当前的通话时长减去,看看他有通话的时间没有了
            if (this.smsCount - card.getNote () >= 1) {
                card.setNote ( card.getNote () + 1 );//如果有的话给他在本生的基础上加1.
            } else if (card.getMoney () - card.getTaocan ().getPric1 () >= 0.1) {//说明他至少也能通话一分钟
                //给他的实际消费加上0.1,因为他套餐的时长用完了,所以要扣钱
                card.setMoney ( card.getMoney () + 0.1 );
                card.setNote ( card.getNote () + 1 );
                card.setConsumAmount ( card.getConsumAmount () + 0.1 );
            } else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X = i;
                try {
                    throw new Exception ( "本次发短信" + i + "条,余额不足。" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }
                return X;

                //直接上抛
            }

        }
        return X;
    }

    //电话返回使用的短信条数
    @Override
    public int call(int in, MoblieCard on)  {
        //用循环实现一分钟的过程吧
        int X = in;
        for (int i = 0; i < in; i++) {
            //当前的通话时长减去,看看他有通话的时间没有了
            if ((this.talkTime - on.getRealTalkTime ()) >= 1) {
                on.setRealTalkTime ( on.getRealTalkTime () + 1 );//如果有的话给他在本生的基础上加1.
            } else if (on.getMoney () - on.getTaocan ().getPric1 () >= 0.2) {//说明他至少也能通话一分钟
                //给他的实际消费加上0.2,因为他套餐的时长用完了,所以要扣钱
                on.setRealTalkTime ( on.getRealTalkTime () + 1 );
                on.setMoney ( on.getMoney () - 0.2 );
                on.setConsumAmount ( on.getConsumAmount () + 0.2 );
            } else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X = i;
                try {
                    throw new Exception ( "本次通话" + i + "分钟余额不足" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }
                return X;



            }

        }
        return X;
    }
}
package sosoyidongyewudating;
//超人套餐
public class SuperPakage extends SerivicePakage implements duanxin,liuliang,tonghua{
    private String tpye="超人套餐";
    private int price=1024;//流量
    private int smsCount=50;//短信
    private int talkTime=200;//通话;


    @Override
    public String getName() {
        return this.tpye;
    }

    public String getTpye() {
        return tpye;
    }

    public void setTpye(String tpye) {
        this.tpye = tpye;
    }

    @Override
    public int getSmsCount() {
        return smsCount;
    }

    @Override
    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    @Override
    public double getPric1() {
        return 78;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getPrice() {
        return price;
    }





    public int getDescrption() {
        return smsCount;
    }

    public void setDescrption(int descrption) {
        this.smsCount = descrption;
    }



    @Override
    public void showInfo() {
        System.out.println("当前套餐是"+this.tpye+",通话时长是"+this.talkTime+"分钟," +
                "短信是:"+this.smsCount+"条,流量是:"+this.price/1024+"G");
    }
    public void shuju(){
        
    }
    //实现消费方法

    @Override
    public int dainxin(int count, MoblieCard card) throws Exception {
        int X=count;
        for (int i = 0; i <count ; i++) {
            //当前的通话时长减去,看看他有通话的时间没有了
            if (this.smsCount-card.getNote ()>=1){
                card.setNote ( card.getNote ()+1 );//如果有的话给他在本生的基础上加1.
            }else if(card.getMoney ()-card.getTaocan ().getPric1 ()>=0.1){//说明他至少也能通话一分钟
                //给他的实际消费加上0.1,因为他套餐的时长用完了,所以要扣钱
                card.setMoney ( card.getMoney ()+0.1 );
                card.setNote ( card.getNote ()+1 );
                card.setConsumAmount ( card.getConsumAmount ()+0.1 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;

                try {
                    throw new Exception ( "本次发短信"+i+"条,余额不足。" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;
            }

        }
        return X;
    }

    @Override
    public int liuliang(int count, MoblieCard card) throws Exception {
        int X=count;
        for (int i = 0; i <count ; i++) {
            //当前的流量减去实际消费的流量,看看他有流量没有有了
            if ((this.price -card.getActual_flow ())>=1){
                card.setActual_flow ( card.getActual_flow ()+1 );//如果有的话给他在本生的基础上加1.
            }else if(card.getMoney ()-card.getTaocan ().getPric1 ()>=0.1){//说明他至少也能通话一分钟
                //给他的实际消费加上0.1,因为他套餐的时长用完了,所以要扣钱
                card.setActual_flow ( card.getActual_flow ()+1 );
                card.setMoney ( card.getMoney ()-0.1 );
                card.setConsumAmount ( card.getConsumAmount ()+0.1 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;

                try {
                    throw new Exception ( "本次上网"+i+"MB余额不足" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;
            }

        }
        return X;
    }

    @Override
    public int call(int in, MoblieCard on) throws Exception {
        int X=in;
        for (int i = 0; i <in ; i++) {
            //当前的通话时长减去,看看他有通话的时间没有了
            if (this.talkTime-on.getRealTalkTime ()>=1){
                on.setRealTalkTime ( on.getRealTalkTime ()+1 );//如果有的话给他在本生的基础上加1.
            }else if(on.getMoney ()-on.getTaocan ().getPric1 ()>=0.2){//说明他至少也能通话一分钟
                //给他的实际消费加上0.2,因为他套餐的时长用完了,所以要扣钱
                on.setRealTalkTime ( on.getRealTalkTime ()+1 );
                on.setMoney ( on.getMoney ()-0.2 );
                on.setConsumAmount ( on.getConsumAmount ()+0.2 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;

                try {
                    throw new Exception ( "本次通话"+i+"分钟余额不足" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;
            }

        }
        return X;
    }
}
package sosoyidongyewudating;
//超人套餐
public class SuperPakage extends SerivicePakage implements duanxin,liuliang,tonghua{
    private String tpye="超人套餐";
    private int price=1024;//流量
    private int smsCount=50;//短信
    private int talkTime=200;//通话;


    @Override
    public String getName() {
        return this.tpye;
    }

    public String getTpye() {
        return tpye;
    }

    public void setTpye(String tpye) {
        this.tpye = tpye;
    }

    @Override
    public int getSmsCount() {
        return smsCount;
    }

    @Override
    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    @Override
    public double getPric1() {
        return 78;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getPrice() {
        return price;
    }





    public int getDescrption() {
        return smsCount;
    }

    public void setDescrption(int descrption) {
        this.smsCount = descrption;
    }



    @Override
    public void showInfo() {
        System.out.println("当前套餐是"+this.tpye+",通话时长是"+this.talkTime+"分钟," +
                "短信是:"+this.smsCount+"条,流量是:"+this.price/1024+"G");
    }
    public void shuju(){
        
    }
    //实现消费方法

    @Override
    public int dainxin(int count, MoblieCard card) throws Exception {
        int X=count;
        for (int i = 0; i <count ; i++) {
            //当前的通话时长减去,看看他有通话的时间没有了
            if (this.smsCount-card.getNote ()>=1){
                card.setNote ( card.getNote ()+1 );//如果有的话给他在本生的基础上加1.
            }else if(card.getMoney ()-card.getTaocan ().getPric1 ()>=0.1){//说明他至少也能通话一分钟
                //给他的实际消费加上0.1,因为他套餐的时长用完了,所以要扣钱
                card.setMoney ( card.getMoney ()+0.1 );
                card.setNote ( card.getNote ()+1 );
                card.setConsumAmount ( card.getConsumAmount ()+0.1 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;

                try {
                    throw new Exception ( "本次发短信"+i+"条,余额不足。" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;
            }

        }
        return X;
    }

    @Override
    public int liuliang(int count, MoblieCard card) throws Exception {
        int X=count;
        for (int i = 0; i <count ; i++) {
            //当前的流量减去实际消费的流量,看看他有流量没有有了
            if ((this.price -card.getActual_flow ())>=1){
                card.setActual_flow ( card.getActual_flow ()+1 );//如果有的话给他在本生的基础上加1.
            }else if(card.getMoney ()-card.getTaocan ().getPric1 ()>=0.1){//说明他至少也能通话一分钟
                //给他的实际消费加上0.1,因为他套餐的时长用完了,所以要扣钱
                card.setActual_flow ( card.getActual_flow ()+1 );
                card.setMoney ( card.getMoney ()-0.1 );
                card.setConsumAmount ( card.getConsumAmount ()+0.1 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;

                try {
                    throw new Exception ( "本次上网"+i+"MB余额不足" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;
            }

        }
        return X;
    }

    @Override
    public int call(int in, MoblieCard on) throws Exception {
        int X=in;
        for (int i = 0; i <in ; i++) {
            //当前的通话时长减去,看看他有通话的时间没有了
            if (this.talkTime-on.getRealTalkTime ()>=1){
                on.setRealTalkTime ( on.getRealTalkTime ()+1 );//如果有的话给他在本生的基础上加1.
            }else if(on.getMoney ()-on.getTaocan ().getPric1 ()>=0.2){//说明他至少也能通话一分钟
                //给他的实际消费加上0.2,因为他套餐的时长用完了,所以要扣钱
                on.setRealTalkTime ( on.getRealTalkTime ()+1 );
                on.setMoney ( on.getMoney ()-0.2 );
                on.setConsumAmount ( on.getConsumAmount ()+0.2 );
            }else {
                //所有条件都不满足的话可以认为他没钱套餐内容用完了也没有了
                X=i;

                try {
                    throw new Exception ( "本次通话"+i+"分钟余额不足" );//直接上抛
                }catch (Exception e) {
                    e.printStackTrace ();
                }return X;
            }

        }
        return X;
    }
}
package sosoyidongyewudating;
//套餐的共有属性及方法
public class SerivicePakage {
    private int smsCount;//短信
    private int price;//流量
    private int talkTime;//通话时间
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }
    
    public int getPrice() {
        return price;
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }


    public void showInfo(){//介绍方法

    }
    public double getPric1() {//资费方法
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}
package sosoyidongyewudating;
//使用场景
public class Scene{
    private String data;//场景介绍
    private String type;//场景消费类型

    private int no;//场景消费数量

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public Scene() {
    }

    public Scene(String data, String type, int no) {
        this.data = data;
        this.type = type;
        this.no = no;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }


}
package sosoyidongyewudating;
//消费记录
public class ConsumInf extends Scene {

    private String number;//手机号
    private String type;//消费类型
    private int quantity;//包括所有消费的数量及短信、流量(MB)、通话时长。

    public ConsumInf() {
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public void setType(String type) {
        this.type = type;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public ConsumInf(String number, String type, int quantity) {
        this.number = number;
        this.type = type;
        this.quantity = quantity;
    }
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值