精华内容
下载资源
问答
  • 嗖嗖移动业务大厅

    2018-12-05 09:58:14
    嗖嗖移动业务大厅,完整的项目工程文件。直接导入即可使用。
  • 本项目嗖嗖移动移动大厅提供了嗖嗖移动用户的常用功能,包括新用户注册、本月账单查询、套餐余量查询,打印消费详单,套餐变更,办理退网、话费充值、、查看消费记录、查看资费说明。另外,还可以模拟用户通话、上网...
  • 实现嗖嗖移动业务大厅java代码实现嗖嗖移动业务大厅java代码
  • *****************不要问我是谁,请叫我雷锋!************
  • JAVA小项目 嗖嗖移动业务大厅 为什么要我写大于50个字节
  • 没有积分可以私聊我,可给你们发网盘资源
  • 嗖嗖移动营业大厅

    2018-04-09 21:35:28
    嗖嗖移动业务大厅,自己写的,不是太完美,Java基础 面向对象 封装继承多态 if条件判断,switch 条件判断,for条件循环,while条件判断,
  • Java 实现嗖嗖移动营业大厅嗖嗖移动业务大厅,自己写的,不是太完美,Java基础 面向对象 封装继承多态 if条件判断,switch 条件判断,for条件循环,while条件判断, 嗖嗖
  • 嗖嗖移动卡(MoblieCard):卡号(cardNumber)、用户名(userName)、密码(passWord)、所属套餐(serPack)、当月消费金额(consumAmount)、账户余额(money)、当月实际通话时长(realTalkTIme)、当月实际发送...
  • 提供的功能包括新用户注册登录、本月账单查询、套餐余量查询、打印消费详单、套餐变更、办理退网、话费充值、查看消费记录、查看资费说明功能,另外可以模拟用户通话、上网、发短信的场景进行相应的扣费。...
  • ACCP8.0S2嗖嗖移动业务大厅ACCP8.0S2嗖嗖移动业务大厅ACCP8.0S2嗖嗖移动业务大厅
  • 这里是程序的主入口
  • 嗖嗖移动营业大厅 功能有用户注册、用户登录(本月账单查询、套餐余量查询、打印消费详单、更换套餐、办理退网)、使用嗖嗖、用户充值、资费说明、退出系统功能,用Java开发的源程序,注册的数据信息可以保存到项目...
  • 嗖嗖移动业务大厅(源码下载+注释全 值得收藏)

    万次阅读 多人点赞 2018-10-20 05:48:26
    嗖嗖移动业务大厅项目(代码+注释全) package info; /* * 消费记录 * @author 苍何 */ public class ConsumInfo { public String cardNumber; public String type;//类型(童话、短信、上网) ...

    嗖嗖移动业务大厅项目(源码+下载+注释全)

    鉴于很多同学找我要源码,特意将源码放在了微信公众号上面,直接就可以下载获取源码,还能获得很多我亲自整理的学习笔记,欢迎关注公众号——苍何之旅,点击下方的菜单栏““嗖嗖源码””
    “”

    源码下载:点我下载
    项目整体框架

    package info;
    /*
     * 消费记录
     * @author 苍何
     */
    public class ConsumInfo {
    	public String cardNumber;
    	public String type;//类型(童话、短信、上网)
    	public int consumDate;//当前消费量 
    	
    	public ConsumInfo() {
    	}
    	public ConsumInfo(String cardNumber, String type, int consumDate) {
    		super();
    		this.cardNumber = cardNumber;
    		this.type = type;
    		this.consumDate = consumDate;
    	}
    }
    `
    
    package info;
    
    import myPackage.ServicePackage;
    
    /*
     * 卡号类
     * @author 苍何
     */
    public class MobileCard {
    	 public String cardNumble;//卡号
    	 public String uesrName;//姓名
    	 public String passWord;//密码
    	 public ServicePackage setPackage;//选择的套餐
    	 public double consumAmount;//消费金额=套餐费+实际消费金额
    	 public double money;//当前余额=充值钱数-consumAmount(消费金额)
    	 public int realTalkTime;//通话时长
    	 public int realSMSCount;//短信条数
    	 public int realFlow;//流量
    	
    	 
    	 public MobileCard() {
    	}
    	 
    
    	public MobileCard(String cardNumble, String uesrName, String passWord,
    			ServicePackage setPackage, double consumAmount, double money,
    			int realTalkTime, int realSMSCount, int realFlow) {
    		super();
    		this.cardNumble = cardNumble;
    		this.uesrName = uesrName;
    		this.passWord = passWord;
    		this.setPackage = setPackage;
    		this.consumAmount = consumAmount;
    		this.money = money;
    		this.realTalkTime = realTalkTime;
    		this.realSMSCount = realSMSCount;
    		this.realFlow = realFlow;
    	}
    
    
    	public void showMeg() {
    		 System.out.println("卡号:" + this.cardNumble + "   用户名:" + this.uesrName + "  当前余额:" + this.money+"元");
    	 }
    	
    }         
    
    
    package info;
    
    import java.util.Random;
    
    /*
     * 使用场景
     * @author 苍何
     */
    public class Scene {
    	public String type;//场景类型
    	public int data;//场景消费数据
    	public String description;//场景描述
    	
    	public Scene() {
    		super();
    	}
    	public Scene(String type, int data, String description) {
    		super();
    		this.type = type;
    		this.data = data;
    		this.description = description;
    	}
    }
    
    
    
    package myPackage;
    
    import info.MobileCard;
    import Service.NetSevice;
    
    /*
     * 网虫套餐
     * @author 苍何
     */
    public class NetPackage extends ServicePackage implements NetSevice {
    	/*
    	 * 上网流量3GB(3*1024M) 
    	 * 资费68元
    	 */
    	public int talkTime = 0;
    	public int smsCount = 0;
    	public int flow=3072;
    	
    	
    	public NetPackage() {
    		super();
    		super.price=68;
    	}
    	
    	public NetPackage(int talkTime, int smsCount, int flow) {
    		super();
    		this.talkTime = talkTime;
    		this.smsCount = smsCount;
    		this.flow = flow;
    	}
    
    	public void showInfo() {
    		System.out.println("网虫套餐:上网流量为3GB/月,资费为68.0元/月。");
    	}
    
    
    	@Override
    	public int netPlay(int flow, MobileCard card)throws Exception {
    		int temp=flow;
    		for(int i=0;i<flow;i++){
    			if(this.flow-card.realFlow>=1){
    				card.realFlow++;
    			}else if(card.money>=0.1){
    				card.realFlow++;
    				//账户余额增加0.1元,消费金额也增加0。1
    				 card.money-=0.1;
    				 card.consumAmount+=0.1;
    			}else{
    				temp=i;
    				throw new Exception("本次上网"+i+"分钟,您的余额不足,请充值后再使用!");
    			}
    		}
    		return temp;
    
    	}
    }
    
    
    package myPackage;
    
    /*
     * 套餐类(父类)
     * @author 苍何
     */
    public abstract class ServicePackage {
    	//套餐月资费
    	public double price;
    	//显示套餐信息
    	public abstract void showInfo();
    }
    
    
    package myPackage;
    
    import info.MobileCard;
    import Service.CallService;
    import Service.NetSevice;
    import Service.SendService;
    
    /*
     * 超人套餐
     * @author 苍何
     */
    public class SuperPackage extends ServicePackage implements CallService,SendService,NetSevice{
    	/*
    	 * 通话时长200分钟
    	 * 上网流量1024MB
    	 * 短信50条
    	 * 资费78元
    	 */
    	public int talkTime=200;
    	public int smsCount=50;
    	public int flow=1024;
    	
    	public SuperPackage(){
    		super();
    		super.price=78;
    	}
    	public SuperPackage(int talkTime, int smsCount, int flow) {
    		super();
    		this.talkTime = talkTime;
    		this.smsCount = smsCount;
    		this.flow = flow;
    	}
    
    
    	public void showInfo() {
    		System.out.println("超人套餐:通话时长为200分钟/月,上网流量为1GB/月,短信条数为50条/月,资费为78.0元/月。");
    	}
    	public int send(int count, MobileCard card) throws Exception{
    		int temp=count;
    		for(int i=0;i<count;i++){
    			if(this.smsCount-card.realSMSCount>=1){
    				card.realSMSCount++;
    			}else if(card.money>=0.1){
    				card.realSMSCount++;
    				//账户余额增加0.1元,消费金额也增加0。1
    				 card.money-=0.1;
    				 card.consumAmount+=0.1;
    			}else{
    				temp=i;
    				throw new Exception("本次发短信"+i+"分钟,您的余额不足,请充值后再使用!");
    			}
    		}
    		return temp;
    		
    	}
    
    	@Override
    	public int call(int miniCount, MobileCard card) throws Exception {
    		int temp=miniCount;
    		for(int i=0;i<miniCount;i++){
    			if(this.talkTime-card.realTalkTime>=1){
    				card.realTalkTime++;
    			}else if(card.money>=0.2){
    				card.realTalkTime++;
    				//账户余额增加0.2元,消费金额也增加0。2
    				 card.money-=0.2;
    				 card.consumAmount+=0.2;
    			}else{
    				temp=i;
    				throw new Exception("本次通话"+i+"分钟,您的余额不足,请充值后再使用!");
    			}
    		}
    		return temp;
    	}
    
    	@Override
    	public int netPlay(int flow, MobileCard card)throws Exception {
    		int temp=flow;
    		for(int i=0;i<flow;i++){
    			if(this.flow-card.realFlow>=1){
    				card.realFlow++;
    			}else if(card.money>=0.1){
    				card.realFlow++;
    				//账户余额增加0.1元,消费金额也增加0。1
    				 card.money-=0.1;
    				 card.consumAmount+=0.1;
    			}else{
    				temp=i;
    				throw new Exception("本次上网"+i+"分钟,您的余额不足,请充值后再使用!");
    			}
    		}
    		return temp;
    		
    	}
    
    	
    	
    }
    
    
    package myPackage;
    
    import info.MobileCard;
    import Service.CallService;
    import Service.SendService;
    
    /*
     * 话唠套餐
     * @author 苍何
     */
    public class TalkPackage extends ServicePackage implements CallService,SendService{
    	/*
    	 * 通话时长500分钟
    	 * 短信30条
    	 * 资费58
    	 */
    	public int talkTime=500;//通话时长
    	public int smsCount=30;//短信
    	public int flow=0;//上网
    	
    	public TalkPackage() {
    		super();
    		super.price=58;
    	}
    	
    	public TalkPackage(int talkTime, int smsCount, int flow) {
    		super();
    		this.talkTime = talkTime;
    		this.smsCount = smsCount;
    		this.flow = flow;
    	}
    
    	public void showInfo() {
    		System.out.println("话唠套餐:通话时长为500分钟/月,短信条数为30条/月,资费为58.0元/月。");
    	}
    	public int send(int count, MobileCard card)throws Exception {
    		int temp=count;
    		for(int i=0;i<count;i++){
    			if(this.smsCount-card.realSMSCount>=1){
    				card.realSMSCount++;
    			}else if(card.money>=0.1){
    				card.realSMSCount++;
    				//账户余额增加0.1元,消费金额也增加0。1
    				 card.money-=0.1;
    				 card.consumAmount+=0.1;
    			}else{
    				temp=i;
    				throw new Exception("本次发短信"+i+"分钟,您的余额不足,请充值后再使用!");
    			}
    		}
    		return temp;
    	}
    	@Override
    	public int call(int miniCount, MobileCard card) throws Exception{
    		int temp=miniCount;
    		for(int i=0;i<miniCount;i++){
    			if(this.talkTime-card.realTalkTime>=1){
    				card.realTalkTime++;
    			}else if(card.money>=0.2){
    				card.realTalkTime++;
    				//账户余额增加0.2元,消费金额也增加0。2
    				 card.money-=0.2;
    				 card.consumAmount+=0.2;
    			}else{
    				temp=i;
    				throw new Exception("本次通话"+i+"分钟,您的余额不足,请充值后再使用!");
    			}
    		}
    		return temp;
    	}
    }
    
    
    package Service;
    
    import info.MobileCard;
    
    /*
     * 打电话(接口)
     * @author 苍何
     */
    public interface CallService {
    	/**
    	 * 套餐内通话免费
    	 * 套餐外通话每分钟0.2元
    	 * 超出电话余额抛出异常提示余额不足
    	 * @param miniCount
    	 * @param card
    	 * @throws Exception 
    	 */
    	public  int call(int miniCount,MobileCard card) throws Exception;
    }
    
    
    package Service;
    
    import info.MobileCard;
    
    /*
     * 上网(接口)
     * @author 苍何
     */
    public interface NetSevice {
    	/**
    	 * 套餐内上网流量免费
    	 * 套餐外每MB0.1元
    	 * 余额不足抛出异常提示余额不足
    	 * @return 
    	 * @throws Exception 
    	 */
    	public int netPlay(int flow,MobileCard card) throws Exception;
    		
    }
    
    
    package Service;
    
    import info.MobileCard;
    
    public interface SendService {
    	/**
    	 * 套餐内短信免费
    	 * 套餐外短信每条1毛
    	 * 余额不足抛出异常
    	 * @author 苍何
    	 * @return 
    	 */
    	public  int send(int count,MobileCard card)throws Exception;
    }
    
    
    package start;
    
    import java.util.Scanner;
    
    /*
     * 管理类
     * @author 苍何
     */
    public class Manage {
    	
    	/**
    	 * 启动(主菜单)
    	 */
    	public void start(){
    		Scanner input = new Scanner(System.in);
    		Util util = new Util();
    		boolean iscontinue = true;// 是否继续
    		do {
    			System.out.println();
    			System.out.println("*************欢迎使用嗖嗖移动业务大厅***************");
    			System.out.println("1.用户登录   2.用户注册   3.使用嗖嗖   4.话费充值  5.资费说明  6.退出系统");
    			System.out.print("请选择:");
    			int option = input.nextInt();
    			switch (option) {
    			case 1:
    				util.login();
    				break;
    			case 2:
    				util.signIn();
    				break;
    			case 3:
    				util.uesSoso();
    				break;
    			case 4:
    				util.addPayMoney();
    				break;
    			case 5:
    				util.ziFei();
    				break;
    			case 6:
    				System.out.println("欢迎您下次继续使用!");
    				iscontinue=false;
    				break;
    			default:
    				System.out.println("输入有误!请重新输入");
    				break;
    			}
    		} while (iscontinue);
    	}
    
    }
    
    
    package start;
    
    public class Start {
    
    	/**
    	 * 启动系统
    	 * @author 苍何
    	 */
    	public static void main(String[] args) {
    		Manage manage=new Manage();
    		manage.start();
    	}
    
    }
    
    
    package start;
    
    import info.ConsumInfo;
    import info.MobileCard;
    import info.Scene;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.io.UnsupportedEncodingException;
    import java.io.Writer;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.Set;
    
    import Service.CallService;
    import Service.NetSevice;
    import Service.SendService;
    
    import myPackage.NetPackage;
    import myPackage.ServicePackage;
    import myPackage.SuperPackage;
    import myPackage.TalkPackage;
    
    /*
     * 业务类(工具类)
     * @author 苍何
     */
    public class Util {
    
    	private static final ServicePackage TalkPackage = null;
    	private static final ServicePackage NetPackage = null;
    	private static final ServicePackage SuperPackage = null;
    	Scanner input = new Scanner(System.in);
    	ServicePackage sp;
    	MobileCard card = new MobileCard();
    	// map集合储存卡号信息,并通过卡号查到对应的姓名等信息
    	Map<String, MobileCard> map = new HashMap<String, MobileCard>();
    	// 所有卡号的消费记录列表
    	Map<String, List<ConsumInfo>> consumInfo = new HashMap<String, List<ConsumInfo>>();
    	// 储存一个卡号的所有消费记录用list集合
    	List<ConsumInfo> list = new ArrayList<ConsumInfo>();
    	// 储存场景列表
    	Map<Integer, Scene> scenes = new HashMap<Integer, Scene>();
    	// 构造6个使用场景
    	Scene scene0 = new Scene("通话", 90, "问候客户,怎知其如此慢,通话90分钟");
    	Scene scene1 = new Scene("通话", 600, "给老婆打电话,问问工作和生活情况,通话600分钟");
    	Scene scene2 = new Scene("短信", 7, "给10086发短信查询相关业务,发送短信7条");
    	Scene scene3 = new Scene("短信", 40, "给妈妈发短信问最近身体状况,发送短信40条");
    	Scene scene4 = new Scene("上网", 2048, "用手机在线观看视频,使用流量2GB");
    	Scene scene5 = new Scene("上网", 1024, "和老婆语音童话,通宵一晚,使用流量1GB");
    
    	/**
    	 * 用户数据初始化
    	 */
    	public void initData() {
    		// 初始化三张手机卡,并添加进集合
    		MobileCard card1 = new MobileCard("13979387057", "大大", "1234",
    				new TalkPackage(), 68, 32, 200, 20, 300);// 话痨套餐
    		MobileCard card2 = new MobileCard("13979387058", "发阿萨德", "12345",
    				new NetPackage(), 78, 22, 100, 10, 3000);// 网虫套餐
    		MobileCard card3 = new MobileCard("13979387059", "当阿萨德", "123456",
    				new SuperPackage(), 88, 12, 200, 20, 500);// 超人套餐
    		map.put("13979387057", card1);
    		map.put("13979387058", card2);
    		map.put("13979387059", card3);
    		// 消费记录初始化
    		ConsumInfo info = new ConsumInfo("13979387057", "通话", 200);
    		list.add(info);
    		consumInfo.put("13979387057", list);
    	}
    
    	/**
    	 * 产生随机的电话号码,返回数组
    	 */
    	public String[] getNum(int count) {// 传入产生几个随机的电话号码
    		String[] nums = new String[9];
    		String number = null;
    		for (int i = 0; i < count; i++) {// count代表循环count次,产生count个随机号码
    			number = "139";// 定义电话号码以139开头
    			Random random = new Random();// 定义random,产生随机数
    			for (int j = 0; j < 8; j++) {
    				// 生成0~9 随机数
    				number += random.nextInt(9);
    			}
    			nums[i] = number;
    		}
    		return nums;
    	}
    
    	/**
    	 * 注册
    	 */
    	public void signIn() {
    		System.out.println("*****可选择的卡号*****");
    		String[] nums = getNum(9);// 产生9个随机号码
    		// 遍历数组
    		for (int i = 0; i < nums.length; i++) {
    			System.out.print((i + 1) + "、" + nums[i] + "\t");
    			// 保证每一行只显示三个号码
    			if ((i + 1) % 3 == 0) {
    				System.out.println();
    			}
    		}
    		System.out.print("请选择卡号(输入1~9的序号):");
    		int cardChose = input.nextInt();
    		if (cardChose < 1 || cardChose > 9) {
    			System.out.println("输入错误!");
    		} else if (!map.containsKey(nums[cardChose - 1])) {
    			card.cardNumble = nums[cardChose - 1];
    		} else {
    			System.out.println("对不起,此号码已被注册,请重新选择");
    		}
    
    		System.out.print("1.话唠套餐  2.网虫套餐  3.超人套餐,  请选择套餐(输入序号):");
    		int packageChose = input.nextInt();
    		System.out.print("请输入姓名:");
    		card.uesrName = input.next();
    		System.out.print("请输入密码:");
    		card.passWord = input.next();
    		System.out.print("请输入预存话费金额:");
    		double pay = input.nextInt();
    		switch (packageChose) {
    		case 1:
    			sp = new TalkPackage();
    			break;
    		case 2:
    			sp = new NetPackage();
    			break;
    		case 3:
    			sp = new SuperPackage();
    			break;
    		default:
    			System.out.println("输入有误!");
    			break;
    		}
    		card.setPackage = sp;
    		card.consumAmount = sp.price;
    		card.money = pay - card.consumAmount;
    
    		// 判断存入的金额是否够叫月租费,如果不够交要循坏让其充值金额。直到金额符合标准方可
    		while (card.money < 0) {
    			System.out.print("您预存的话费金额不足以支付本月固定套餐资费,请重新充值:");
    			pay = input.nextInt();
    			card.money = pay - card.consumAmount;
    		}
    		// 将信息放入集合
    		map.put(card.cardNumble, card);
    		if (map.containsKey(card.cardNumble)) {
    			card.showMeg();
    			sp.showInfo();
    			System.out.println("注册成功!");
    		} else {
    			System.out.println("注册失败,请重新注册!");
    		}
    	}
    
    	/**
    	 * 登陆
    	 */
    	public void login() {
    		System.out.print("请输入手机卡号:");
    		String yourNumber = input.next();
    		System.out.print("请输入密码:");
    		String yourPassWord = input.next();
    		if (map.containsKey(yourNumber)) {
    			if (map.get(yourNumber).passWord.equals(yourPassWord)) {
    				boolean flag = true;// 循环标记
    				do {
    					System.out.println();
    					System.out.println("*****嗖嗖移动用户菜单*****");
    					System.out
    							.print("1.本月账单查询\n2.套餐余量查询\n3.打印消费详单\n4.套餐变更\n5.办理退网\n请选择(输入1~5选择功能,其他键返回上一级):");
    					int functionChose = input.nextInt();
    					switch (functionChose) {
    					case 1:
    						// 本月账单查询
    						showAmountDetail(yourNumber);
    						break;
    					case 2:
    						// 套餐余量查询
    						showRemaiDetail(yourNumber);
    						break;
    					case 3:
    						// 打印消费详单
    						printAmountDetail(yourNumber);
    						break;
    					case 4:
    						// 套餐变更
    						changePackage(yourNumber);
    						break;
    					case 5:
    						// 办理退网
    						delateCard(yourNumber);
    						break;
    					default:
    						// 退出二级菜单
    						flag = false;
    						break;
    					}
    				} while (flag);
    
    			} else {
    				System.out.println("密码输入错误!");
    			}
    
    		} else {
    			System.out.println("对不起,您输入的信息有误,无法登录!");
    		}
    
    	}
    
    	/**
    	 * 当月账单查询
    	 */
    	public void showAmountDetail(String yourNumber) {
    		// 本月账单查询
    		System.out.println();
    		System.out.println("*****本月账单查询******");
    		System.out.println("您的卡号:" + yourNumber + ",当月账单:");
    		System.out.println("套餐资费:" + sp.price + "元");
    		System.out.println("合计:" + dataFormat(map.get(yourNumber).consumAmount)
    				+ "元");
    		System.out.println("账户余额:" + dataFormat(map.get(yourNumber).money)
    				+ "元");
    	}
    
    	/**
    	 * 套餐余量查询
    	 */
    	public void showRemaiDetail(String yourNumber) {
    		System.out.println();
    		System.out.println("*****套餐余量查询******");
    		System.out.println("您的卡号:" + yourNumber + ",套餐内剩余:");
    		StringBuffer meg = new StringBuffer();
    		int remainTalkTime;
    		int remainSmsCount;
    		int remainFlow;
    		if (map.get(yourNumber).setPackage instanceof TalkPackage) {
    			TalkPackage cardPackage = (TalkPackage) (map.get(yourNumber).setPackage);
    			// 若是话痨套餐,若套餐内通话时间比实际通话时间大。则用套餐内通话时间-实际通话时间。否则返回0.
    			remainTalkTime = cardPackage.talkTime > map.get(yourNumber).realTalkTime ? cardPackage.talkTime
    					- card.realTalkTime
    					: 0;
    			meg.append("童话时长:" + remainTalkTime + "分钟\n");
    			remainSmsCount = cardPackage.smsCount > map.get(yourNumber).realSMSCount ? cardPackage.smsCount
    					- map.get(yourNumber).realSMSCount
    					: 0;
    			meg.append("短信条数:" + remainSmsCount + "条\n");
    		} else if (map.get(yourNumber).setPackage instanceof NetPackage) {
    			NetPackage cardPackage = (NetPackage) (map.get(yourNumber).setPackage);
    			remainFlow = cardPackage.flow > map.get(yourNumber).realFlow ? cardPackage.flow
    					- map.get(yourNumber).realFlow
    					: 0;
    			meg.append("上网流量:" + remainFlow + "M\n");
    		} else if (map.get(yourNumber).setPackage instanceof SuperPackage) {
    			SuperPackage cardPackage = (SuperPackage) (map.get(yourNumber).setPackage);
    			remainTalkTime = cardPackage.talkTime > map.get(yourNumber).realTalkTime ? cardPackage.talkTime
    					- map.get(yourNumber).realTalkTime
    					: 0;
    			meg.append("童话时长:" + remainTalkTime + "分钟\n");
    			remainSmsCount = cardPackage.smsCount > map.get(yourNumber).realSMSCount ? cardPackage.smsCount
    					- map.get(yourNumber).realSMSCount
    					: 0;
    			meg.append("短信条数:" + remainSmsCount + "条\n");
    			remainFlow = cardPackage.flow > map.get(yourNumber).realFlow ? cardPackage.flow
    					- map.get(yourNumber).realFlow
    					: 0;
    			meg.append("上网流量:" + remainFlow + "M\n");
    		}
    		System.out.println(meg);
    	}
    
    	/**
    	 * 打印消费详单
    	 */
    	public void printAmountDetail(String yourNumber) {
    		Set<String> numbles = consumInfo.keySet();// 获取所有的消费记录map集合中的号码
    		// 遍历set集合,判断次卡号是否存在消费记录
    		Iterator<String> it = numbles.iterator();
    		// 判断消费列表中是否有此卡的消费记录
    		boolean isExist = false;// false不存在
    		while (it.hasNext()) {
    			String numbleKey = it.next();
    			if (numbleKey.equals(yourNumber)
    					&& consumInfo.get(yourNumber).size() != 0) {
    				isExist = true;
    			}
    		}
    		// 如果存在此卡消费记录,则打印,不存在则说明
    		if (isExist) {
    			StringBuffer brf = new StringBuffer("*******" + yourNumber
    					+ "消费记录*******\n");
    			brf.append("序号\t类型\t数据(通话(分钟)/上网(M)/短信(条)\n");
    			List<ConsumInfo> infos = consumInfo.get(yourNumber);
    			// 遍历消费记录列表
    			for (int i = 0; i < infos.size(); i++) {
    				brf.append((i + 1) + "\t" + infos.get(i).type + "\t"
    						+ infos.get(i).consumDate + "\n");
    			}
    			// 采用字符输出流打印
    			Writer os = null;
    			BufferedWriter bw = null;
    			try {
    				os = new FileWriter("消费记录.txt");
    				bw = new BufferedWriter(os);
    				bw.write(brf.toString());
    				bw.flush();
    				System.out.println("消费记录打印完毕!");
    			} catch (IOException e) {
    				e.printStackTrace();
    			} finally {
    				try {
    					bw.close();
    					os.close();
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    			}
    		} else {
    			System.out.println("对不起,不存在此卡的消费记录,不能打印!");
    		}
    	}
    
    	/**
    	 * 套餐变更
    	 */
    	public void changePackage(String yourNumber) {
    		boolean isCoreact = true;// 标记,套餐是否正确变更
    		System.out.print("1.话唠套餐  2.网虫套餐  3.超人套餐,  请重新选择套餐(输入序号):");
    		int optionrevie = input.nextInt();
    		switch (optionrevie) {
    		case 1:
    			sp = new TalkPackage();
    			if (map.get(yourNumber).setPackage instanceof TalkPackage) {
    				System.out.println("您已是此套餐,无需变更!");
    			} else {
    				map.get(yourNumber).setPackage = TalkPackage;
    				System.out.println("套餐更改成功!");
    			}
    
    			break;
    		case 2:
    			sp = new NetPackage();
    			if (map.get(yourNumber).setPackage instanceof NetPackage) {
    				System.out.println("您已是此套餐,无需变更!");
    			} else {
    				map.get(yourNumber).setPackage = NetPackage;
    				System.out.println("套餐更改成功!");
    			}
    			break;
    		case 3:
    			sp = new SuperPackage();
    			if (map.get(yourNumber).setPackage instanceof SuperPackage) {
    				System.out.println("您已是此套餐,无需变更!");
    			} else {
    				map.get(yourNumber).setPackage = SuperPackage;
    				System.out.println("套餐更改成功!");
    			}
    
    			break;
    		default:
    			System.out.println("请输入正确的序号!");
    			break;
    		}
    
    	}
    
    	/**
    	 * 办理退网
    	 */
    	public void delateCard(String yourNumber) {
    		// 加个判断防止用户手误输入错误
    		System.out.print("您确定注销此手机号码吗?Y/N:");
    		String chouseyes = input.next();
    		if (chouseyes.equalsIgnoreCase("Y")) {
    			map.remove(yourNumber);
    			System.out.println("您已成功注销该手机号!");
    		}
    	}
    
    	/**
    	 * 使用嗖嗖
    	 */
    	public void uesSoso() {
    		// 将初始化的场景放入map集合中,通过手机号键值对应起来
    		scenes.put(0, scene0);
    		scenes.put(1, scene1);
    		scenes.put(2, scene2);
    		scenes.put(3, scene3);
    		scenes.put(4, scene4);
    		scenes.put(5, scene5);
    
    		System.out.print("请输入手机卡号:");
    		String yourNumber = input.next();
    		System.out.print("请输入密码:");
    		String yourPassWord = input.next();
    		if (map.containsKey(yourNumber)) {
    			if (map.get(yourNumber).passWord.equals(yourPassWord)) {
    				card = map.get(yourNumber);
    				ServicePackage pack = card.setPackage;
    				Random random = new Random();
    				int ranNum = 0;
    				int temp = 0;// 记录每个场景中的实际消费
    				boolean iscontinued = true;// 停下
    				do {
    					ranNum = random.nextInt(6);// 随机产生0-5的随机数
    					Scene scene = scenes.get(ranNum);// 随机产生的一个值对应一个场景scene
    					switch (ranNum) {
    					case 0:
    					case 1:
    						// 判断卡所属的套餐是否有打电话的功能
    						if (pack instanceof CallService) {
    							System.out.println(scene.description);
    							try {
    								temp = ((CallService) pack).call(scene.data,
    										card);
    							} catch (Exception e) {
    								// TODO Auto-generated catch block
    								e.printStackTrace();
    							}
    							// 添加一条消费记录
    							list.add(new ConsumInfo(yourNumber, scene.type,
    									temp));
    							iscontinued = false;
    							break;
    
    						} else {
    							// 如果该卡套餐不支持通话功能,则重新生成随机数选择其他场景
    							continue;
    						}
    
    					case 2:
    					case 3:
    						// 判断卡所属的套餐是否有发短信的功能
    						if (pack instanceof SendService) {
    							System.out.println(scene.description);
    							try {
    								temp = ((SendService) pack).send(scene.data,
    										card);
    							} catch (Exception e) {
    								e.printStackTrace();
    							}
    							// 添加一条消费记录
    							list.add(new ConsumInfo(yourNumber, scene.type,
    									temp));
    							iscontinued = false;
    							break;
    						} else {
    							// 如果该卡套餐不支持发短信功能,则重新生成随机数选择其他场景
    							continue;
    						}
    					case 4:
    					case 5:
    						// 判断卡所属的套餐是否有上网的功能
    						if (pack instanceof NetSevice) {
    							System.out.println(scene.description);
    							try {
    								temp = ((NetSevice) pack).netPlay(scene.data,
    										card);
    							} catch (Exception e) {
    								e.printStackTrace();
    							}
    							// 添加一条消费记录
    							list.add(new ConsumInfo(yourNumber, scene.type,
    									temp));
    							iscontinued = false;
    							break;
    						} else {
    							// 如果该卡套餐不支持上网功能,则重新生成随机数选择其他场景
    							continue;
    						}
    					}
    					System.out.println("添加一条消费记录!");
    					consumInfo.put(yourNumber, list);
    				} while (iscontinued);
    			} else {
    				System.out.println("密码输入错误!");
    			}
    
    		} else {
    			System.out.println("对不起,您输入的信息有误,无法登录!");
    		}
    
    	}
    
    	/**
    	 * 话费充值
    	 */
    	public void addPayMoney() {
    		System.out.print("请输入您要充值的手机号码:");
    		String yourNumber = input.next();
    		System.out.print("请输入您要充值手机号码的密码:");
    		String yourPassWord = input.next();
    		if (map.containsKey(yourNumber)) {
    			if (map.get(yourNumber).passWord.equals(yourPassWord)) {
    				System.out.print("请输入您要充值的金额:");
    				double payMoney = input.nextDouble();
    				map.get(yourNumber).money += payMoney;
    				System.out.println("话费充值成功,您当前话费余额" + map.get(yourNumber).money
    						+ "元");
    			} else {
    				System.out.println("密码输入错误!");
    			}
    		} else {
    			System.out.println("对不起,您输入的信息有误,无法登录!");
    		}
    
    	}
    
    	/**
    	 * 资费说明
    	 */
    	public void ziFei() {
    		System.out.println();
    		InputStream is = null;
    		InputStreamReader isr = null;
    		BufferedReader br = null;
    		try {
    			is = new FileInputStream("资费说明.txt");
    			isr = new InputStreamReader(is, "GBK");
    			br = new BufferedReader(isr);
    			String info =null;
    			while((info=br.readLine())!=null){
    				System.out.println(info);
    			}
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (UnsupportedEncodingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally{
    			try {
    				br.close();
    				isr.close();
    				is.close();
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    
    	}
    
    	/**
    	 * 数学计算科学计数法转换格式(保留两位小数的方法)
    	 */
    	public String dataFormat(double data) {
    		DecimalFormat format = new DecimalFormat("##.00");
    		return format.format(data);
    	}
    
    	/**
    	 * 两位数相减保留一位小数的方法
    	 */
    	public double sub(double num1, double num2) {
    		return (num1 * 10 - num2 * 10) / 10;
    	}
    }
    
    
    *****资费说明******
    套餐类型:话唠套餐
    通话时长:200分钟 
    短信条数:50条
    月资费:58元
    ——————————————
    套餐类型:网虫套餐
    上网流量:5GB
    月资费:68元
    ——————————————
    套餐类型:超人套餐
    通话时长:200分钟 
    短信条数:100条
    上网流量:1GB
    月资费:78元
    ——————————————
    超出套餐计费:
    通话时长:0.2/分钟
    短信条数:0.1/分钟
    上网流量:0.1/分钟
    
    
    *******13948368681消费记录*******
    序号	类型	数据(通话(分钟)/上网(M)/短信(条)
    1	短信	40
    2	通话	600
    3	通话	0
    
    

    ``欢迎来我的GitHub下载源码,是开源免费的!
    鉴于有些同学找不到我的项目在GitHub位置,直接点击此链接就可以下载,这样下载:https://github.com/freestylefly/SOSO

    在这里插入图片描述

    顺便帮忙点击一波关注哈,万分感谢:
    在这里插入图片描述
    GitHub如果你不熟悉,可以点击这个:
    https://blog.csdn.net/qq_43270074/article/details/83445607


    本文章已同步至我的GitHub仓库:Javastudy,期待您的加入😊

    本文章已同步至苍何的个人博客,可以直接在博客上留言哦😊

    来我的微信公众号玩耍呗😊

    扫码无套路关注我的CSDN博客😊

    展开全文
  • JavaOOP项目 - 嗖嗖移动业务大厅

    千次阅读 2020-12-28 19:39:43
    JavaOOP项目 - 嗖嗖移动业务大厅 项目目录结构 服务接口 通讯服务接口 package ServicePackage; //通讯服务 public interface CallService { int call(int minCount); } 短信服务接口 package Service...

    JavaOOP项目 - 嗖嗖移动业务大厅


    项目目录结构

    在这里插入图片描述


    服务接口

    • 通讯服务接口
    package ServicePackage;
    //通讯服务
    public interface CallService {
        int call(int minCount);
    }
    
    • 短信服务接口
    package ServicePackage;
    //短信服务
    public interface SendService {
        int sendMessage(int count);
    }
    
    
    • 网络服务接口
    package ServicePackage;
    //上网服务
    public interface NetService {
        int netPlay(int flow);
    }
    

    套餐类

    • 基本套餐类
    package ServicePackage;
    //套餐类
    public abstract class ServicePackage implements NetService,CallService,SendService{
        private String type;//套餐类型
        private double price;//资费
        private int flow;//流量
        private int talkTime;//通话时长
        private int smsCount;//短信条数
        int Sjs;//随机数
    
        public ServicePackage() { }
    
        public String getType() {
            return type;
        }
    
        void setType(String type) {
            this.type = type;
        }
    
        public double getPrice() {
            return price;
        }
    
        void setPrice(double price) {
            this.price = price;
        }
    
        public int getFlow() {
            return flow;
        }
    
        public void setFlow(int flow) {
            this.flow = flow;
        }
    
        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;
        }
    
        public int getSjs() {
            return Sjs;
        }
    
        public abstract void showInfo();//资费信息
    
        //生成使用数据
        public void showSjs(){
            Sjs =  (int)((Math.random()*9)+1);
        }
    
        @Override
        public int call(int minCount) {
            showSjs();
            System.out.println("打了个电话,使用了"+Sjs+"分钟通话时长");
            return minCount - Sjs;//返回使用后的剩余数据
        }
    
        @Override
        public int netPlay(int flow) {
            showSjs();
            System.out.println("上了个网,使用了"+Sjs+"G流量");
            return flow - Sjs;
        }
    
        @Override
        public int sendMessage(int count) {
            showSjs();
            System.out.println("发了一手短信,使用了"+Sjs+"条短信");
            return count - Sjs;
        }
    }
    
    • 网虫套餐
    package ServicePackage;
    //网虫套餐
    public class NetPackage extends ServicePackage implements NetService{
    
        public NetPackage(){
            setType("网虫套餐");//套餐类型
            setFlow(40);//流量
            setPrice(19);//费用
        }
    
        @Override
        public void showInfo() {
            System.out.println("套餐类型:" + getType());
            System.out.println("上网流量:" + getFlow() + "G/月");
            System.out.println("月租:" + getPrice() + "元/月");
        }
    
        @Override
        public int netPlay(int flow) {
            showSjs();
            System.out.println("网上冲浪看mm,使用了"+Sjs+"G流量");
            return flow - Sjs;
        }
    }
    
    • 话痨套餐
    package ServicePackage;
    //话痨套餐
    public class TalkPackage extends ServicePackage implements CallService,SendService{
    
        public TalkPackage() {
            setType("话痨套餐");//套餐类型
            setTalkTime(300);//通话时长
            setSmsCount(100);//短信条数
            setPrice(66);//资费信息
        }
    
        @Override
        public void showInfo() {
            System.out.println("套餐类型:" + getType());
            System.out.println("通话时长:" + getTalkTime() + "分钟/月");
            System.out.println("短信条数:" + getSmsCount() + "条/月");
            System.out.println("月租:" + getPrice() + "元/月");
        }
    
        @Override
        public int call(int minCount) {
            showSjs();
            System.out.println("和好老表唠了会嗑,使用了"+Sjs+"分钟通话时间");
            return minCount - Sjs;
        }
    
        @Override
        public int sendMessage(int count) {
            showSjs();
            System.out.println("给MZ发短信,使用了"+Sjs+"条短信");
            return count - Sjs;
        }
    }
    
    • 超人套餐
    package ServicePackage;
    //超人套餐
    public class SuperPackage extends ServicePackage implements CallService,NetService,SendService{
    
        public SuperPackage() {
            setType("超人套餐");//套餐类型
            setTalkTime(500);//通话时长
            setSmsCount(200);//短信条数
            setFlow(80);//流量
            setPrice(199);//资费信息
        }
    
        @Override
        public void showInfo() {
            System.out.println("套餐类型:" + getType());
            System.out.println("通话时长:" + getTalkTime() + "分钟/月");
            System.out.println("短信条数:" + getSmsCount() + "条/月");
            System.out.println("上网流量:" + getFlow() + "G/月");
            System.out.println("月租:" + getPrice() + "元/月");
        }
    
        @Override
        public int call(int minCount) {
            showSjs();
            System.out.println("和好老表唠了会嗑,使用了"+Sjs+"分钟通话时间");
            return minCount - Sjs;
        }
    
        @Override
        public int netPlay(int flow) {
            showSjs();
            System.out.println("网上冲浪看抖音,使用了"+Sjs+"G流量");
            return flow - Sjs;
        }
    
        @Override
        public int sendMessage(int count) {
            showSjs();
            System.out.println("给MZ发短信,使用了"+Sjs+"条短信");
            return count - Sjs;
        }
    }
    

    手机卡类

    package SosoMgr;
    
    import ServicePackage.ServicePackage;
    
    //手机卡,用户
    public class MobileCard {
        private String UserName;//用户名
        private String Password;//用户密码
        private String CardNum;//卡号
        private ServicePackage SerPackage;//套餐
        private double consumAmount;//累计消费金额
        private double money;//余额(可用)
        private int realTalkTime;//语言时长(可用)
        private int realSMSCount;//短信条数(可用)
        private int realFlow;//流量(可用)
    
        public MobileCard() {}
    
        public String getUserName() {
            return UserName;
        }
    
        public void setUserName(String userName) {
            UserName = userName;
        }
    
        public String getPassword() {
            return Password;
        }
    
        public void setPassword(String password) {
            Password = password;
        }
    
        public String getCardNum() {
            return CardNum;
        }
    
        public void setCardNum(String cardNum) {
            CardNum = cardNum;
        }
    
        public ServicePackage getSerPackage() {
            return SerPackage;
        }
    
        public void setSerPackage(ServicePackage serPackage) {
            SerPackage = serPackage;
        }
    
        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 int getRealFlow() {
            return realFlow;
        }
    
        public void setRealFlow(int realFlow) {
            this.realFlow = realFlow;
        }
    }
    

    消费信息

    package SosoMgr;
    
    //消费信息
    public class ConsumInfo {
        private String cardNumber;//卡号
        private String type;//套餐类型
        private String consumData;//消费数据
    
        public ConsumInfo() {}
    
        public ConsumInfo(String cardNumber, String type, String consumData) {
            this.cardNumber = cardNumber;
            this.type = type;
            this.consumData = consumData;
        }
    
        public String getCardNumber() {
            return cardNumber;
        }
    
        public void setCardNumber(String cardNumber) {
            this.cardNumber = cardNumber;
        }
    
        public String getType() {
            return type;
        }
    
        public void setType(String type) {
            this.type = type;
        }
    
        public String getConsumData() {
            return consumData;
        }
    
        public void setConsumData(String consumData) {
            this.consumData = consumData;
        }
    }
    

    注册系统

    package SosoMgr;
    
    import ServicePackage.ServicePackage;
    
    import java.util.*;
    
    //注册系统
    public class RegistSystem {
        private String CardNumber;//所选卡号
        private ServicePackage tcSP;//所选套餐
        private String UserName;//用户名
        private String Password;//用户密码
        private double money;//预存话费
    
        private RegistSystem(){}
    
        static MobileCard RegistSys(List<ServicePackage> SerPack){
            Scanner SR = CardUtil.SR;
            RegistSystem rs = new RegistSystem();
            System.out.println("******************可选择卡号******************");
            List<String> cards = new ArrayList<>(rs.cardSJ());//生成可用卡号
            for(int i = 0;i < cards.size();i++){//遍历可用卡号集
                System.out.print((i+1)+"、"+cards.get(i)+"\t");//输出可用卡号
                if((i+1)%3==0){//每打印三次后换行
                    System.out.print("\n");
                }
            }
            do{
                String Z_card = "[1-9]";
                System.out.print("请选择卡号(输入1-9的序号):");
                String xzCard = SR.next();//选择卡号序号
                if(xzCard.matches(Z_card)){
                    int xzCardI = Integer.parseInt(xzCard);
                    rs.CardNumber = cards.get(xzCardI-1);//获取对应序号的号码
                    break;
                }else{
                    System.out.println("输入错误,无此选项!");
                }
            }while(true);
    
            System.out.println("******************可选套餐******************");
            for(int i = 0;i < SerPack.size();i++){//遍历套餐集
                System.out.print((i+1)+"、"+SerPack.get(i).getType()+"\n");
            }
            do{
                String Z_card = "[1-"+ SerPack.size() +"]";
                System.out.print("请选择套餐:");
                String xzTaoCan = SR.next();//选择套餐
                if(xzTaoCan.matches(Z_card)){
                    int tcI = Integer.parseInt(xzTaoCan);
                    rs.tcSP = SerPack.get(tcI-1);//获取对应序号的套餐
                    break;
                }else{
                    System.out.println("输入错误,无此选项!");
                }
            }while(true);
            System.out.println("-----------------------------------------------");
            do{
                System.out.print("请设置姓名:");
                String Z_Name = "[\\D&&\\S]{2,6}";
                String userName = SR.next();//设置名字
                if(userName.matches(Z_Name)){
                    rs.UserName = userName;//保存名字
                    break;
                }else{
                    System.out.println("名字不符合规范!\n名字中不能含有数字,并大于2个不大于6个字符");
                }
            }while(true);
    
            do{
                System.out.print("请设置密码:");
                String Z_password = "\\S{6,16}";
                String password = SR.next();//设置密码
                if(password.matches(Z_password)){
                    rs.Password = password;//保存密码
                    break;
                }else{
                    System.out.println("密码不符合规范!\n密码要大于6位不大于16位");
                }
            }while(true);
    
            do{
                System.out.print("预存话费金额:");
                String Z_money = "\\d*";
                String S_money = SR.next();//输入存入话费
                if(S_money.matches(Z_money)){
                    double mon = Double.parseDouble(S_money);
                    if(mon > rs.tcSP.getPrice()){//判断存入话费是否大于所选套餐资费
                        rs.money = mon;//保存存入话费
                        break;
                    }else{
                        System.out.println("存入的话费必须大于套餐月租!");
                    }
                }else{
                    System.out.println("输入错误!请输入数字!");
                }
            }while(true);
    
            MobileCard mCard = rs.caedSet();//制作手机卡,并接收制作好的手机卡
            System.out.println("注册成功!\n卡号:"+mCard.getCardNum()
                    +" 、用户名:"+mCard.getUserName()
                    +" 、余额(已扣除月租):"+mCard.getMoney());//打印客户信息
            rs.tcSP.showInfo();//打印套餐信息
            return mCard;//返回制作完成的手机卡
        }
    
        //手机卡制作系统,将数据刻录入手机卡,并返回制作好的手机卡
        private MobileCard caedSet(){
            MobileCard mCard = new MobileCard();//获取初始(空白)手机卡
            mCard.setCardNum(CardNumber);//给手机卡设置号码
            mCard.setUserName(UserName);//给手机卡设置名字
            mCard.setPassword(Password);//给手机卡设置密码
            mCard.setSerPackage(tcSP);//给手机卡设置套餐
            //设置手机卡初始余额,扣除套餐月租
            double price = mCard.getSerPackage().getPrice();//获取手机卡套餐月租
            mCard.setMoney(money-price);//将月租扣除,并设置余额
            mCard.setConsumAmount(price);//记录已扣除费用
            mCard.setRealTalkTime(mCard.getSerPackage().getTalkTime());//设置手机卡初始语音时长
            mCard.setRealSMSCount(mCard.getSerPackage().getSmsCount());//设置手机卡初始短信条数
            mCard.setRealFlow(mCard.getSerPackage().getFlow());//设置手机卡初始流量
    
            //返回用户信息
            return mCard;
        }
    
        //卡号生成系统
        private Set cardSJ(){
            CardUtil cu = CardUtil.cuObject();//工具类对象
            Set<String> Cards = new HashSet<>();//可用卡号集
            for(int a = 0;a<9;a++){//生成9个可用号码
                String cardnum = "199";//初始卡号开头
                for(int i = 0;i<8;i++){//随机生成8位整数
                    cardnum += (int)(Math.random()*10);
                }
                boolean ja = false;
                if(!cu.cards.containsKey(cardnum)){//判断新生成的手机号是否已存在
                    ja = Cards.add(cardnum);//将手机号添加进集合
                }
                if(!ja){//若手机号添加失败,则重新进行添加
                    a--;
                }
            }
            return Cards;
        }
    }
    

    工具类

    package SosoMgr;
    
    import ServicePackage.*;
    import java.io.*;
    import java.util.*;
    
    //工具类
    public class CardUtil {
        public static Scanner SR = new Scanner(System.in);
        List<ServicePackage> SerPack = new ArrayList<>();//套餐集
        Map<String,MobileCard> cards = new HashMap<>();//手机卡集、手机号 对应 手机卡
        Map<String,List<ConsumInfo>> ConsumInfos = new HashMap<>();//消费信息集、手机号 对应 消费信息
        {
            //将套餐存入套餐集
            SerPack.add(new NetPackage());
            SerPack.add(new TalkPackage());
            SerPack.add(new SuperPackage());
        }
        private CardUtil(){}
        private static CardUtil cu = new CardUtil();//工具类对象
        public static CardUtil cuObject(){
            return cu;//返回工具类对象
        }
    
        //注册,将手机卡存入手机卡集
        void registCard(){
            MobileCard mCard = RegistSystem.RegistSys(SerPack);//启动注册系统,传入套餐集,并接收制作好的手机卡
            cards.put(mCard.getCardNum(),mCard);//将手机号与对应的手机卡存入集合
            //给手机号绑定消费记录集
            List<ConsumInfo> consumInfos = new ArrayList<>();//消费信息集
            ConsumInfos.put(mCard.getCardNum(),consumInfos);//将手机号与与消费信息集存入集合
        }
    
        //登录
        MobileCard LoginMenu(String monbileNumber){//传入手机号
            boolean Pcn = cards.containsKey(monbileNumber);//判断手机卡集中是否存在此手机号
            if(Pcn){
                MobileCard card = cards.get(monbileNumber);//获取指定手机号对应的手机卡
                System.out.print("请输入密码:");
                String passwd = SR.next();
                if(card.getPassword().equals(passwd)){
                    return card;//密码输入正确后返回对应手机卡
                }else{
                    System.out.println("密码错误!");
                }
            }else{
                System.out.println("此号码不存在!");
            }
            return null;
        }
    
        //充值话费
        public void InputMoney(String monbileNumber){
            if(cards.containsKey(monbileNumber)){//判断手机卡集中是否存在此手机号
                System.out.print("请输入充值金额:");
                double inputMoney = 0;
                try {
                    Scanner s = new Scanner(System.in);
                    inputMoney = s.nextDouble();
                    //s.close();
                }catch(Exception e){}
                if(inputMoney > 0){
                    MobileCard card = cards.get(monbileNumber);//获取指定手机号对应的手机卡
                    card.setMoney(card.getMoney() + inputMoney);//将充值金额加入余额
                    System.out.println("卡号:"+monbileNumber+"的用户,充值成功!\n余额:"+card.getMoney());
                }else{
                    System.out.println("充值失败!");
                }
            }else{
                System.out.println("此号码不存在!");
            }
        }
    
        //使用嗖嗖
        public void RunSoso(String monbileNumber){
            //调用功能传入剩余用量,使用功能后扣除使用量,返回剩余用量
            boolean Pcn = cards.containsKey(monbileNumber);//判断手机卡集中是否存在此手机号
            if(Pcn){
                MobileCard card = cards.get(monbileNumber);//获取传入手机号对应手机卡
                ServicePackage SerPac = card.getSerPackage();//获取手机卡的套餐
                if(card.getMoney() > 0){//判断是否还有余额
                    //记录消费信息
                    List<ConsumInfo> coninf = ConsumInfos.get(monbileNumber);//获取对应手机号的消费记录集
                    ConsumInfo Con = new ConsumInfo(monbileNumber,SerPac.getType(),"");
                    coninf.add(Con);
                    System.out.println("\t1.拨打电话");
                    System.out.println("\t2.发送短信");
                    System.out.println("\t3.网上冲浪");
                    System.out.println("**********************************");
                    System.out.print("请输入:");
                    String xzSo = SR.next();
                    switch(xzSo){
                        case "1":
                            int TalkTime = SerPac.call(card.getRealTalkTime());//调用通话方法,传入可用通话时长,返回使用后的时长
                            int T = SerPac.getSjs();//消耗的时长
                            if(TalkTime < 0){//判断是否还有剩余用量
                                double M = T * 0.2;//用超出的时长 乘以 每次超出1的费用 得出超出的费用
                                card.setConsumAmount(card.getConsumAmount() + M);//记录消费金额
                                card.setMoney(card.getMoney() - M);//用原有的钱扣除使用的钱,得出余额
                            }
                            card.setRealTalkTime(TalkTime);//更改使用后的时长
    
                            Con.setConsumData("号码:"+Con.getCardNumber()+" 套餐:"+Con.getType()+" 使用了电话功能 使用时长:"+T+"分钟");
                            break;
                        case "2":
                            int SMSCount = SerPac.sendMessage(card.getRealSMSCount());
                            int S = SerPac.getSjs();
                            if(SMSCount < 0){
                                double M = S * 0.1;
                                card.setConsumAmount(card.getConsumAmount() + M);//记录消费金额
                                card.setMoney(card.getMoney() - M);
                            }
                            card.setRealSMSCount(SMSCount);
    
                            Con.setConsumData("号码:"+Con.getCardNumber()+" 套餐:"+Con.getType()+" 使用了短信功能 使用条数:"+S+"条");
                            break;
                        case "3":
                            int Flow = SerPac.netPlay(card.getRealFlow());
                            int F = SerPac.getSjs();
                            if(Flow < 0){
                                double M = F * 3;
                                card.setConsumAmount(card.getConsumAmount() + M);//记录消费金额
                                card.setMoney(card.getMoney() - M);
                            }
                            card.setRealFlow(Flow);
    
                            Con.setConsumData("号码:"+Con.getCardNumber()+" 套餐:"+Con.getType()+" 使用了上网功能 使用流量:"+F+"G");
                            break;
                        default:
                            System.out.println("返回上一级...");
                    }
                }else{
                    System.out.println("余额不足!请尽快缴费!");
                }
            }else{
                System.out.println("此号码不存在!");
            }
        }
    
        //打印消费详单
        public void OutXF(String cardNum){
            List<ConsumInfo> Conl = ConsumInfos.get(cardNum);//获取手机号对应的套餐集
            if(!Conl.isEmpty()){
                File fi = new File("消费记录");
                fi.mkdirs();
                File f = new File(fi , cardNum +"消费记录单.txt");
                try {
                    Writer w = new FileWriter(f);
                    for(ConsumInfo i : Conl){
                        w.write(i.getConsumData()+"\n");
                        w.flush();//强制让输出流输出数据
                    }
                    System.out.println("打印成功,请在消费记录目录下查看详单");
                    w.close();
                } catch (IOException e) {
                    System.out.println("出错,打印失败!");
                }
            }else{
                System.out.println("暂无消费记录,无法打印!");
            }
        }
    
        //资费说明
        public void PriceInfo(){
            System.out.println("\n*****************资费说明*****************");
            for(ServicePackage ser : SerPack){
                ser.showInfo();
                System.out.println("-----------------------");
            }
            System.out.println("超出套餐计费:");
            System.out.println("通话时长:0.2元/分钟");
            System.out.println("短信条数:0.1元/条");
            System.out.println("上网流量:3元/G");
        }
    
        //手机号判断
        public Object[] cardNumIf(){
            Object[] StrBoo = new Object[2];//Object类型数组,储存手机号与布尔值
            String Z_cardNum = "[0-9]{11}";//11位并只能为0-9中的数字
            System.out.print("请输入手机卡号:");
            String cardNum = SR.next();
            if(cardNum.matches(Z_cardNum)){
                StrBoo[0] = cardNum;//存入手机号
                StrBoo[1] = true;
            }else{
                StrBoo[0] = "手机号必须为11位整数";
                StrBoo[1] = false;
            }
            return StrBoo;
        }
    }
    

    业务大厅

    package SosoMgr;
    
    import ServicePackage.ServicePackage;
    
    import java.util.Scanner;
    
    //嗖嗖移动业务大厅
    public class SosoMgr {
        Scanner SR = CardUtil.SR;
        CardUtil cu = CardUtil.cuObject();//工具类对象
        public static void main(String[] args) {
            SosoMgr sm = new SosoMgr();
            boolean FH_SouYie = false;//用于判断是否返回大厅首页
            do{
                FH_SouYie = sm.mainMenu();//启动主菜单
            }while(FH_SouYie);
            sm.SR.close();
        }
    
        //主菜单
        private boolean mainMenu() {
            System.out.println("\n******************欢迎使用嗖嗖移动业务大厅******************");
            System.out.println("\t1.用户登录");
            System.out.println("\t2.用户注册");
            System.out.println("\t3.使用嗖嗖");
            System.out.println("\t4.话费充值");
            System.out.println("\t5.资费说明");
            System.out.println("\t6.退出系统");
            System.out.println("*********************************************************");
            System.out.print("请选择:");
            String SY_XuanZe = SR.next();
            //首页选择
            switch (SY_XuanZe){
                case "1"://用户登录
                    Object[] StrBoo = cu.cardNumIf();
                    String Card_Ts = (String)StrBoo[0];
                    boolean bool = (boolean)StrBoo[1];
                    if(bool){
                        MobileCard card = cu.LoginMenu(Card_Ts);
                        if(card != null){
                            cardMenu(card);
                        }
                    }else{
                        System.out.println(Card_Ts);
                    }
                    return true;
                case "2"://用户注册
                    cu.registCard();//调用工具类中注册系统
                    return true;
                case "3"://使用嗖嗖
                    System.out.println("\n*****************使用嗖嗖*****************");
                    Object[] StrBoo3 = cu.cardNumIf();
                    String Card_Ts3 = (String)StrBoo3[0];
                    boolean bool3 = (boolean)StrBoo3[1];
                    if(bool3){
                        cu.RunSoso(Card_Ts3);
                    }else{
                        System.out.println(Card_Ts3);
                    }
                    return true;
                case "4"://话费充值
                    Object[] StrBoo4 = cu.cardNumIf();
                    String Card_Ts4 = (String)StrBoo4[0];
                    boolean bool4 = (boolean)StrBoo4[1];
                    if(bool4){
                        cu.InputMoney(Card_Ts4);
                    }else{
                        System.out.println(Card_Ts4);
                    }
                    return true;
                case "5"://资费说明
                    cu.PriceInfo();
                    return true;
                case "6"://退出系统
                    System.out.println("感谢您使用嗖嗖移动业务");
                    return false;
                default:
                    System.out.println("无此选项!");
                    return true;
            }
        }
    
        //登录菜单
        private void cardMenu(MobileCard card){
            boolean xzPD = false;
            String cardNum = card.getCardNum();//手机号
            String Uname = card.getUserName();//用户名
            do{
                System.out.println("*******嗖嗖移动用户菜单*******");
                System.out.println("\t1.本月账单查询");
                System.out.println("\t2.套餐余量查询");
                System.out.println("\t3.打印消费详单");
                System.out.println("\t4.套餐更变");
                System.out.println("\t5.办理退网");
                System.out.println("*****************************");
                System.out.print("请选择:");
                String loginXZ = SR.next();
                switch(loginXZ){
                    case "1":
                        System.out.println("******本月账单查询******");
                        System.out.println("卡号:" + cardNum + "的用户:" + Uname + "你好!");
                        System.out.println("当月账单:");
                        System.out.println("\t套餐资费:" + card.getSerPackage().getPrice() + "元");
                        System.out.println("\t累计消费:" + Double.valueOf(String.format("%.1f" , card.getConsumAmount())) + "元");
                        System.out.println("\t账户余额:" + Double.valueOf(String.format("%.1f",card.getMoney())) + "元");
                        xzPD = true;
                        break;
                    case "2":
                        System.out.println("******套餐余量查询******");
                        System.out.println("卡号:" + cardNum + "的用户:" + Uname + "你好!");
                        System.out.println("套餐内剩余(负数代表超出):");
                        System.out.println("\t通话时长:" + card.getRealTalkTime() + "分钟");
                        System.out.println("\t短信条数:" + card.getRealSMSCount() + "条");
                        System.out.println("\t可用流量:" + card.getRealFlow() + "G");
                        xzPD = true;
                        break;
                    case "3":
                        System.out.println("******打印消费详单******");
                        cu.OutXF(cardNum);
                        xzPD = true;
                        break;
                    case "4":
                        System.out.println("******套餐更变******");
                        for(int i = 0;i<cu.SerPack.size();i++){//遍历套餐集
                            System.out.print((i+1)+"、"+cu.SerPack.get(i).getType()+"  ");
                        }
                        System.out.println("\n********************");
                        System.out.print("请选择:");
                        String Z_card = "[1-"+ cu.SerPack.size() +"]";
                        String xzGBs = SR.next();
                        if(xzGBs.matches(Z_card)){
                            int xzGB = Integer.parseInt(xzGBs);
                            String YcardT = card.getSerPackage().getType();//获取现套餐类型
                            ServicePackage SerPac = cu.SerPack.get(xzGB-1);//获取所选套餐
                            if(card.getMoney() >= SerPac.getPrice()){//判断当前手机卡余额,是否可抵扣要更换套餐的月租
                                card.setSerPackage(SerPac);//更改套餐
                                card.setRealTalkTime((card.getRealTalkTime()<0?0:card.getRealTalkTime()) + card.getSerPackage().getTalkTime());//加入更改套餐的语音时长
                                card.setRealSMSCount((card.getRealSMSCount()<0?0:card.getRealSMSCount()) + card.getSerPackage().getSmsCount());//加入更改套餐的短信条数
                                card.setRealFlow((card.getRealFlow()<0?0:card.getRealFlow()) + card.getSerPackage().getFlow());//加入更改套餐的流量
                                card.setMoney(card.getMoney() - card.getSerPackage().getPrice());//扣除更改套餐的月租
                                System.out.println("更变套餐成功!" + YcardT + " --> " + card.getSerPackage().getType());
                            }else{
                                System.out.println("套餐更变失败!可用余额不足以抵扣月租");
                            }
                        }else{
                            System.out.println("无此套餐!");
                        }
                        xzPD = true;
                        break;
                    case "5":
                        System.out.println("******办理退网******");
                        cu.cards.remove(cardNum);//删除指定手机号与对应手机卡
                        System.out.println("卡号:"+cardNum+"的用户,办理退网成功!\n谢谢使用");
                        xzPD = false;
                        break;
                    default:
                        System.out.println("返回上级菜单...");
                        xzPD = false;
                }
            }while(xzPD);
        }
    }
    
    展开全文
  • 嗖嗖移动业务大厅,包含老师的讲解和附加功能,将注册的账号保存为文本格式,下次运行时输入流读入,可以运用上次注册的账号
  • 嗖嗖移动大厅项目

    2019-01-09 08:41:54
    嗖嗖移动大厅项目
  • Java基础 面向对象 封装继承多态 if条件判断,switch 条件判断,for条件循环,while条件判断,
  • 作业~嗖嗖移动业务大厅

    千次阅读 2020-06-09 09:44:52
    测试类 业务类 @author Chen HuiHong @author 2020年6月6日{time} @Tel 18073799961 */ public class TestSosoMgr { public static Scanner se = new Scanner(System.in); public static CardUtil cardUtil=...

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    /**

    • 测试类 业务类

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class TestSosoMgr {
      public static Scanner se = new Scanner(System.in);
      public static CardUtil cardUtil=new CardUtil();
      public static MobileCard mobileCard = new MobileCard();
      public static Cousumlnfo cousumlnfo = new Cousumlnfo();
      public static Scene scene = new Scene();
      public static void main(String[] args) {
      // TODO Auto-generated method stub
      start();
      }
      public static void start() {//一级菜单
      do {
      System.out.println("**欢迎使用橙橙 移动业务大厅");
      System.out.println(“1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统”);

       	System.out.println("请选择--");
       	int num = se.nextInt();
       	
       	switch (num) {
       	case 1:
       		System.out.println("******用户登录*****");
       		System.out.print("请输入手机号:");
       		String number = se.next();
       		System.out.print("请输入密码:");
       		String passWord = se.next();
       		boolean bos = cardUtil.isExistCard(number, passWord);
       		if (bos) {
       			cardMenu(number);
       		}
       		break;
       	case 2:
       		System.out.println("******可选者卡号*****");
       		registCard();
       		 
       		break;
       	case 3:
       		System.out.println("******使用橙橙*****");
       		System.out.print("请输入手机号:");
       		String number2 = se.next();
       		cardUtil.userSoso(number2);
       		break;
       	case 4:
       		System.out.println("******话费充值*****");
       		System.out.print("请输入手机号:");
       		String number3 = se.next();
       		System.out.print("请输入充值金额:");
       		double money = se.nextDouble();
       		cardUtil.chargeMoney(number3,money);
       		break;
       	case 5:
       		System.out.println("******资费说明*****");
       		cardUtil.showDescription();
       		break;
       	case 6:
       		System.out.println("******退出系统*****");
       		System.exit(0);
       		break;
       	default:
       		System.out.println("******输入的选项不正确,请重新输入*****");
       		break;
       	}
       } while (true);
      

      }
      public static void cardMenu(String number) {//二级菜单
      boolean bbs = true;
      do {
      System.out.println(“嗖嗖移动用户菜单”);
      System.out.println(“1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)”);

       	int num = se.nextInt();
       	switch (num) {
       	case 1:
       		System.out.println("******本月账单查询*****");
       		cardUtil.showAmountDetail(number);
       		break;
       	case 2:
       		System.out.println("******套餐余量查询*****");
       		cardUtil.showRemainDetail(number);
       		break;
       	case 3:
       		System.out.println("******打印消费详单*****");
       		cardUtil.prinConsumlnfo(number);;
       		break;
       	case 4:
       		System.out.println("******套餐变更*****");
       		System.out.print("请输入要变更的套餐类型:");
       		System.out.print("1.话痨套餐  2.网虫套餐  3.超人套餐\t请选择序号");
       		int packNum = se.nextInt();
       		cardUtil.changingPack(number, packNum);
       		break;
       	case 5:
       		System.out.println("******办理退网*****");
       		cardUtil.delCard(number);
       		break;
       	default:
       		bbs = false;
       		
       	}
       } while (bbs);
       System.out.println("谢谢使用***");
      

      }
      //用户注册流程
      public static void registCard() {
      String[] cardNumber = cardUtil.getNewNumbers(9);
      System.out.println(“请选择卡号(输入1~9的序号)”);
      int num2 =se.nextInt();
      mobileCard.setCardNumber(cardNumber[num2]);
      cardUtil.addCard(mobileCard);
      System.out.print(“1.话痨套餐 2.网虫套餐 3.超人套餐\t请选择序号”);
      int num = se.nextInt();
      ServicePackage talkPackage = cardUtil.createPack(num);
      if (talkPackage instanceof TalkPackage) {
      talkPackage = (TalkPackage)talkPackage;
      mobileCard.setSerPackage(talkPackage);
      System.out.print(“请输入姓名:”);
      String name = se.next();
      mobileCard.setUserName(name);
      System.out.print(“请输入密码:”);
      String passWord= se.next();
      mobileCard.setPassWord(passWord);
      double money;
      System.out.println(“请输入预存话费金额:”);
      do {
      money = se.nextDouble();
      if (money<talkPackage.price) {
      System.out.print("您预存的话费金额不足以支付本月固定套餐费,请重新输入: ");
      }
      } while (money < talkPackage.price);
      cardUtil.chargeMoney(cardNumber[num2], money);
      cousumlnfo.setCardNumber(cardNumber[num2]);

       	//mobileCard.setMoney(money);
       	boolean bos = cardUtil.isExistCard(cardNumber[num2]);
       	if (bos) {
       		System.out.println("注册成功:");
       		mobileCard.setMoney(money-talkPackage.price);
       		cardUtil.printAmountDetail(cardNumber[num2]);
       		talkPackage.shownlfo();
       	}
       }
       if (talkPackage instanceof Netpackage) {
       	talkPackage = (Netpackage)talkPackage;
       	mobileCard.setSerPackage(talkPackage);
       	System.out.print("请输入姓名:");
       	String name = se.next();
       	mobileCard.setUserName(name);
       	System.out.print("请输入密码:");
       	String passWord= se.next();
       	mobileCard.setPassWord(passWord);
       	double money;
       	System.out.println("请输入预存话费金额:");
       	do {
       		money = se.nextDouble();
       		if (money<talkPackage.price) {
       			System.out.print("您预存的话费金额不足以支付本月固定套餐费,请重新输入: ");
       		}
       	} while (money < talkPackage.price);
       	cardUtil.chargeMoney(cardNumber[num2], money);
       	cousumlnfo.setCardNumber(cardNumber[num2]);
       	//mobileCard.setMoney(money);
       	boolean bos = cardUtil.isExistCard(cardNumber[num2]);
       	if (bos) {
       		System.out.println("注册成功:");
       		mobileCard.setMoney(money-talkPackage.price);
       		cardUtil.printAmountDetail(cardNumber[num2]);
       		talkPackage.shownlfo();
       	}
       }
       if (talkPackage instanceof SuperPackage) {
       	talkPackage =(SuperPackage)talkPackage;
       	mobileCard.setSerPackage(talkPackage);
       	System.out.print("请输入姓名:");
       	String name = se.next();
       	mobileCard.setUserName(name);
       	System.out.print("请输入密码:");
       	String passWord= se.next();
       	mobileCard.setPassWord(passWord);
       	double money;
       	System.out.println("请输入预存话费金额:");
       	do {
       		money = se.nextDouble();
       		if (money<talkPackage.price) {
       			System.out.print("您预存的话费金额不足以支付本月固定套餐费,请重新输入: ");
       		}
       	} while (money < talkPackage.price);
       	cardUtil.chargeMoney(cardNumber[num2], money);
       	cousumlnfo.setCardNumber(cardNumber[num2]);
       	//mobileCard.setMoney(money);
       	boolean bos = cardUtil.isExistCard(cardNumber[num2]);
       	if (bos) {
       		System.out.println("注册成功:");
       		mobileCard.setMoney(money-talkPackage.price);
       		cardUtil.printAmountDetail(cardNumber[num2]);
       		talkPackage.shownlfo();
       	}
       }
      

      }

    }

    /**

    • 工具类

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class CardUtil {
      //存放用户列表
      public static Map<String , MobileCard> cards =new HashMap<String, MobileCard>() ;

      //存放卡号消费记录
      public static Map<String , List> consumlnfos = new HashMap<String, List>();

      Scene scene = new Scene();
      Cousumlnfo cousumlnfo = new Cousumlnfo();
      //初始化场景
      public String initScenes(int key) {

       String type = null;
       switch (key) {
       case 1:
       	type = "通话 ,问候客户,谁知其如此难缠,通话90分钟"; 
       	scene.setDescription(type);
       	cousumlnfo.setType("通话");
       	scene.setData(90);
       	scene.setType("通话");
       	break;
       case 2:
       	type = "通话 ,询问妈妈身体状况,本地通话30分钟"; 
       	scene.setDescription(type);
       	cousumlnfo.setType("通话");
       	scene.setData(30);
       	scene.setType("通话");
       	break;
       
       case 3:
       	type = "短信 ,参与环境保护实施方案问卷调查,发送短信5条";
       	scene.setDescription(type);
       	cousumlnfo.setType("短信");
       	scene.setData(5);
       	scene.setType("短信");
       	break;
       case 4:
       	type = "短信 ,通知朋友换手机,发送短信50条"; 
       	scene.setDescription(type);
       	cousumlnfo.setType("短信");
       	scene.setData(50);
       	scene.setType("短信");
       	break;
       case 5:
       	type = "上网 ,和女友微信视屏聊天,使用流量1GB"; 
       	scene.setDescription(type);
       	cousumlnfo.setType("上网");
       	scene.setData(1024);
       	scene.setType("上网");
       	break;
       case 6:
       	type = "上网,晚上手机在线看亮剑,看得过瘾,使用流量2GB,剩下的日子干瞪眼~~"; 
       	scene.setDescription(type);
       	cousumlnfo.setType("上网");
       	scene.setData(1024*2);
       	scene.setType("上网");
       	break;
       }
       return type;
      

      }
      //注册新卡
      public void addCard(MobileCard card) {
      cards.put(card.getCardNumber(),card );
      }

      //话费充值
      public void chargeMoney(String number,double money){
      cards.get(number).setMoney( cards.get(number).getMoney() +money);
      System.out.println(“账户余额:” + cards.get(number).getMoney()
      );

      }

      //使用嗖嗖
      public void userSoso(String number) {
      MobileCard card = cards.get(number);//获取卡号对象
      ServicePackage pack = card.getSerPackage();//获取持卡所属套餐
      Random random = new Random();
      int ranNum = 0;
      int temp = 0;//记录各场景中的实际消费数据
      boolean bos = true;//定位有没有使用成功
      do {

       	ranNum = random.nextInt(6)+1;
       	
       	//Scene scene = new Scene();
       	scene.setType(initScenes(ranNum));
       	switch (ranNum) {
       	case 1:
       		if (pack instanceof CallServixe) {
       			//执行通话方法
       			System.out.println(scene.getDescription());
       			CallServixe callServixe = (CallServixe)pack;
       			try {
       				temp = callServixe.call(scene.getData(), card);
       				
       			} catch (Exception e) {
       				// TODO Auto-generated catch block
       				e.printStackTrace();
       			}
       			//添加一条记录
       			addConsuminfo(number, new Cousumlnfo(number,scene.getType(),temp));
       			bos = false;
       			break;
       		}else {
       			//如果该卡套餐不支持通话功能,则重新生成随机数选择其他场景
       			continue;
       		}
       		
       	case 2:
       		if (pack instanceof CallServixe) {
       			//执行通话方法
       			System.out.println(scene.getDescription());
       			CallServixe callServixe = (CallServixe)pack;
       			try {
       				temp = callServixe.call(scene.getData(), card);
       			} catch (Exception e) {
       				// TODO Auto-generated catch block
       				e.printStackTrace();
       			}
       			//添加一条记录
       			addConsuminfo(number, new Cousumlnfo(number,scene.getType(),temp));
       			bos = false;
       			break;
       		}else {
       			//如果该卡套餐不支持通话功能,则重新生成随机数选择其他场景
       			continue;
       		}
       	
       	case 3:
       		if (pack instanceof SendService) {
       			//执行发短信方法
       			System.out.println(scene.getDescription());
       			SendService sendService = (SendService)pack;
       			try {
       				temp = sendService.send(scene.getData(), card);
       			} catch (Exception e) {
       				// TODO Auto-generated catch block
       				e.printStackTrace();
       			}
       			//添加一条记录
       			addConsuminfo(number, new Cousumlnfo(number,scene.getType(),temp));
       			bos = false;
       			break;
       		}else {
       			//如果该卡套餐不支持短信功能,则重新生成随机数选择其他场景
       			continue;
       		}
       		
       	case 4:
       		if (pack instanceof SendService) {
       			//执行发短信方法
       			System.out.println(scene.getDescription());
       			SendService sendService = (SendService)pack;
       			try {
       				temp = sendService.send(scene.getData(), card);
       			} catch (Exception e) {
       				// TODO Auto-generated catch block
       				e.printStackTrace();
       			}
       			//添加一条记录
       			addConsuminfo(number, new Cousumlnfo(number,scene.getType(),temp));
       			bos = false;
       			break;
       		}else {
       			//如果该卡套餐不支持短信功能,则重新生成随机数选择其他场景
       			continue;
       		} 
       		
       	case 5:
       		if (pack instanceof NetService) {
       			//执行上网方法
       			System.out.println(scene.getDescription());
       			NetService netService = (NetService)pack;
       			try {
       				temp = netService.netPlay(scene.getData(), card);
       			} catch (Exception e) {
       				// TODO Auto-generated catch block
       				e.printStackTrace();
       			}
       			//添加一条记录
       			addConsuminfo(number, new Cousumlnfo(number,scene.getType(),temp));
       			bos = false;
       			break;
       		}else {
       			//如果该卡套餐不支持上网功能,则重新生成随机数选择其他场景
       			continue;
       		} 
       		
       	case 6:
       		if (pack instanceof NetService) {
       			//执行上网方法
       			System.out.println(scene.getDescription());
       			NetService netService = (NetService)pack;
       			try {
       				temp = netService.netPlay(scene.getData(), card);
       			} catch (Exception e) {
       				// TODO Auto-generated catch block
       				e.printStackTrace();
       			}
       			//添加一条记录
       			addConsuminfo(number, new Cousumlnfo(number,scene.getType(),temp));
       			bos = false;
       			break;
       		}else {
       			//如果该卡套餐不支持上网功能,则重新生成随机数选择其他场景
       			continue;
       		} 				
       	}
       } while (bos);
      

      }

      //资费说明
      public void showDescription() {
      System.out.println(“品牌套餐\t\t话痨套餐\t网虫套餐\t超人套餐”);
      System.out.println(“通话时长(分钟)\t500mim\t\t200mim”);
      System.out.println(“上网流量(GB)\t\t3GB\t1GB”);
      System.out.println(“短信条数(条)\t30条\t\t50条”);
      System.out.println(“资费(元/月)\t58\t68\t78”);
      System.err.println(“超出通话:0.2元/分钟”);
      System.err.println(“超出短信:0.1元/条”);
      System.err.println(“超出流量:0.1元/M”);

      }

      //本月账单查询
      public void showAmountDetail(String number) {
      System.out.println("=====================================================");

       System.out.println("您的卡号:" + number );
       	System.out.println("套餐资费:" + cards.get(number).serPackage.price );
       	System.out.println("合计==:" + cards.get(number).serPackage.price 
       			+ cards.get(number).getConsumAmount()  );
       	System.out.println("账户余额:" + cards.get(number).getMoney()
       			);
       System.out.println("=====================================================");
       MobileCard card;//要查询的卡
       card = cards.get(number);//获取集合中一个元素
       StringBuffer meg = new StringBuffer();
       meg.append("您的卡号:" + card.getCardNumber() +"单月账单");
       meg.append("套餐资费:" + card.getSerPackage().getPrice()+"元\n");
       meg.append("合计:" + Common.dataFormat(card.getConsumAmount())+"元\t");
       meg.append("账户余额:" +Common.dataFormat(card.getMoney()) + "元");
      

      System.out.println(meg);

      }

      //套餐余流量查询 instanceof 判断属于哪个套餐的卡
      public void showRemainDetail(String number){
      if (cards.get(number).serPackage instanceof SuperPackage) {
      SuperPackage superPackage = (SuperPackage)cards.get(number).serPackage;
      System.out.println(“您的卡号:” + number );
      System.out.println(“通话时长:” + superPackage.getTalkTime()+“分钟” );
      System.out.println(“短信条数:” + superPackage.getSmsCount()+ “条” );
      System.out.println(“上网流量:” + superPackage.getFlow()/1024 + “,GB”);
      }
      if (cards.get(number).serPackage instanceof Netpackage) {
      Netpackage superPackage = (Netpackage)cards.get(number).serPackage;
      System.out.println(“您的卡号:” + number );
      //System.out.println(“通话时长:” + cards.get(number).realTalkTime );
      //System.out.println(“短信条数:” + superPackage.getSmsCount() );
      System.out.println(“上网流量:” + superPackage.getFlow()/1024 + “,GB”);
      }
      if (cards.get(number).serPackage instanceof TalkPackage) {
      TalkPackage superPackage = (TalkPackage)cards.get(number).serPackage;
      System.out.println(“您的卡号:” + number );
      System.out.println(“通话时长:” + cards.get(number).realTalkTime +“分钟” );
      System.out.println(“短信条数:” + superPackage.getSmsCount() + “条”);
      //System.out.println(“上网流量:” + superPackage.getFlow());
      }

      }

      //打印消费详单
      public void printAmountDetail(String number){
      System.out.println(“卡号:” + number + “用户名:”

      • cards.get(number).userName +",当前余额:" + cards.get(number).getMoney());
        }
        //打印消费信息
        public void prinConsumlnfo(String number) {
        File file = new File(“消费信息.txt”);
        try {
        file.createNewFile();
        } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        }
        //Writer fileWriter = null;
        try(Writer fileWriter = new FileWriter(number + file);
        ) {
        /*
        * Set numberS= consumlnfos.keySet(); ArrayList< String> arrayList = new
        * ArrayList(); for (String string : numberS) { arrayList.add(string); }
        * List info = new ArrayList();
        /
        //储存指定卡的所有消费记录
        //现有消费列表中是否存在此卡号消费记录,
        boolean isExist =false;
        //String lengString ="";
        List infos= new ArrayList();
        for (String cousumlnfo : consumlnfos.keySet()) {
        if (cousumlnfo.equals(number)) {
        infos=consumlnfos.get(cousumlnfo);
        System.err.println(“我的标记”);
        isExist =true;
        }
        }
        if (isExist) {
        StringBuffer contentBuffer = new StringBuffer("
        *****"+ number +“消费记录” + “******\n”);
        contentBuffer.append(“序号\t类型\t数据\t(通话(分钟)/上网(MB)/短信(条)\n)”);
        for (int i = 0; i < infos.size(); i++) {
        Cousumlnfo cousumlnfo = infos.get(i);
        contentBuffer.append((i+1)+"\t"+cousumlnfo.getType()+
        “\t”+cousumlnfo.getConsumData()+"\n" );
        System.err.println(“我的标记2”);
        }
        fileWriter.write(contentBuffer.toString());
        fileWriter.flush();
        System.out.println(“消费记录打印完毕”);
        }else {
        System.out.println(“对不起,不存在此号码的消费记录,不能打印!”);
        }
        } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

      }

      //套餐变更
      public void changingPack(String number,int packNum){
      //如果剩余费用不够支持新的套餐费用
      if (cards.get(number).getMoney() < cards.get(number).getSerPackage().getPrice()) {
      System.out.println(“余额不足,请充值”);
      }else {
      cards.get(number).setRealTalkTime(0);
      cards.get(number).setRealFlow(0);
      cards.get(number).setRealSMSCount(0);
      cards.get(number).setSerPackage(createPack(packNum));
      cards.get(number).setMoney(cards.get(number).getMoney()-cards.get(number).getSerPackage().getPrice());
      System.out.println(“套餐更换完成”);
      cards.get(number).getSerPackage().shownlfo();
      }

      }

      //办理退网
      public void delCard(String number){
      System.out.println(“账户可退余额为:”+cards.get(number).getMoney());
      cards.get(number).setRealTalkTime(0);
      cards.get(number).setRealFlow(0);
      cards.get(number).setRealSMSCount(0);
      System.err.println("====账号删除");
      cards.remove(number);
      consumlnfos.remove(number);

      }

      //根据卡号和密码查看是否注册
      public boolean isExistCard(String number,String passWord) {
      Set numbers = cards.keySet();
      for (String string : numbers) {
      String searString = string;
      if (searString.equals(number) && (cards.get(searString).getPassWord().equals(passWord))) {
      return true;
      }
      }
      return false;
      }

      //根据卡号查验证是否注册
      public Boolean isExistCard(String number){
      Set numbers = cards.keySet();
      for (String string : numbers) {
      String searString = string;
      if (searString.equals(number)) {
      return true;
      }
      }
      return false;
      }

      //随机生成卡号
      public String createNumber() {
      Random random = new Random();
      boolean dis = false;
      String number = “”;
      int temp = 0;
      do {
      dis = false;//标志位重置为false,用于控制外层循环
      do {
      temp = random.nextInt(100000000);
      } while (temp < 10000000);
      //生成之前,前面加 139
      number = “139” + temp;

       	//和现有用户的卡号比较,不能重复
       		Set<String> cardNumder = cards.keySet();
       		for (String cardNumders : cardNumder) {
       			if (number.equals(cardNumders)) {
       				dis =true;
       				break;
       			}
       		}
       } while (dis);
       
       return number;
      

      }

      //生成指定个数卡号列表
      public String[] getNewNumbers(int count) {
      String[] num = new String[count];
      for (int i = 1; i < 10; i++) {
      try {
      num[i-1] = createNumber();
      System.out.print( i+"."+num[i-1] + “\t”);
      } catch (Exception e) {
      System.out.println(“用户注册异常了”);
      e.printStackTrace();
      }
      if (i%3==0) {
      System.out.println();
      }
      }
      return num;
      }

      //添加指定卡号的消费记录
      public void addConsuminfo(String number ,Cousumlnfo info) {
      if (consumlnfos.containsKey(number)) {
      consumlnfos.get(number).add(info);
      }else {
      List cousumlnfo =new ArrayList();
      try {
      cousumlnfo.add(info);
      } catch (Exception e) {
      System.out.println(e.getMessage());

       		e.printStackTrace();
       	}
       	consumlnfos.put(number, cousumlnfo);
       }
      

      }

      //根据用户选择的套餐序号返回套餐对象
      public ServicePackage createPack(int packlf) {
      ServicePackage servicePackage = null;
      switch (packlf) {
      case 1:
      servicePackage = new TalkPackage();
      break;
      case 2:
      servicePackage = new Netpackage();
      break;
      case 3:
      servicePackage = new SuperPackage();
      break;

       default:
       	break;
       }
       return servicePackage;
      

      }
      }
      /**

    • 接口 通话

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      /
      public interface CallServixe {
      public int call(int minCount,MobileCard card) throws Exception;
      //通话方法 minCount 通话时长 MobileCard 超出套餐内的通话时长需要消费那张卡的余额
      }
      /
      *

    • 上网 接口

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      /
      public interface NetService {
      public int netPlay(int flaw,MobileCard card) throws Exception;
      //flaw上网流量大小 MobileCard 超出流量后的收费
      }
      /
      *

    • 接口 短信

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      /
      public interface SendService {
      public int send(int count,MobileCard card) throws Exception;
      //count发送短信条数 MobileCard 超出后的收费
      }
      /
      *

    • 公共类

    • @author Chen HuiHong

    • @author 2020年6月7日{time}

    • @Tel 18073799961
      /
      public class Common {
      public static String dataFormat(double data) {
      DecimalFormat format = new DecimalFormat("#.0");
      return format.format(data);
      }
      public static double sub(double money ,double num) {
      return money-num;
      }
      }
      /
      *

    • 消费记录

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class Cousumlnfo {
      public String cardNumber;//卡号
      public String type;// 消费类型
      public int consumData;//消费数据

      public Cousumlnfo() {
      super();
      }
      public Cousumlnfo(String cardNumber, String type, int consumData) {
      super();
      this.cardNumber = cardNumber;
      this.type = type;
      this.consumData = consumData;
      }
      public String getCardNumber() {
      return cardNumber;
      }
      public void setCardNumber(String cardNumber) {
      this.cardNumber = cardNumber;
      }
      public String getType() {
      return type;
      }
      public void setType(String type) {
      this.type = type;
      }
      public int getConsumData() {
      return consumData;
      }
      public void setConsumData(int consumData) {
      this.consumData = consumData;
      }

    }

    • 移动卡类

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class MobileCard {
      public String cardNumber;//卡号
      public String userName;//用户民
      public String passWord ;//密码
      public double consumAmount;//消费金额
      public double money;//账户余额
      public int realTalkTime ;//当月实际通话时长
      public int realSMSCount ;//当月实际发送短信条数
      public int realFlow;//当月实际上网流量
      public ServicePackage serPackage;//

      public String getCardNumber() {
      return cardNumber;
      }

      public void setCardNumber(String cardNumber) {
      this.cardNumber = cardNumber;
      }

      public String getUserName() {
      return userName;
      }

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

      public String getPassWord() {
      return passWord;
      }

      public void setPassWord(String passWord) {
      this.passWord = passWord;
      }

      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 int getRealFlow() {
      return realFlow;
      }

      public void setRealFlow(int realFlow) {
      this.realFlow = realFlow;
      }

      public ServicePackage getSerPackage() {
      return serPackage;
      }

      public void setSerPackage(ServicePackage serPackage) {
      this.serPackage = serPackage;
      }

      public void showMeg() {

      }

    }
    /**

    • 网虫套餐

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class Netpackage extends ServicePackage implements NetService{
      public int flow;//上网流量

      public Netpackage() {
      this.flow =3*1024;
      super.price = 68;
      }

      public int getFlow() {
      return flow;
      }

      public void setFlow(int flow) {
      this.flow = flow;

      }

      @Override
      public void shownlfo() {
      // TODO Auto-generated method stub
      super.shownlfo();
      System.out.println(“网虫套餐:”
      + “上网流量为:”+this.flow/1024 +“GB/月。”
      );
      }

      @Override
      //flaw上网流量大小 MobileCard 超出流量后的收费
      public int netPlay(int flaw, MobileCard card) throws Exception {
      int temp = flaw;
      for (int i = 0; i < flaw; i++) {
      if (this.flow- card.getRealFlow() >= 1) {
      //第一种情况:套餐剩余通话时长可以支持1分钟通话
      card.setRealFlow(card.getRealFlow() +1); //实际通话时长加1

       	}else if (card.getMoney() >=0.1) {
       		//第二种情况: 套餐通话时长已用完,账户余额可以支付1分钟通话,使用账户余额支付
       		card.setRealFlow(card.getRealFlow() +1);//实际通话时长加1 
       		//账户余额消费0.1元(一分钟额外电话)
       		card.setMoney(Common.sub(card.getMoney(), 0.1));
       		card.setConsumAmount(card.getConsumAmount() + 0.1);
       	} else {
       		temp = i;
       		throw new Exception("本次已用流量" +i+"M,您的余额不足,请充值后在使用!");
       		
       	}
       }
       this.setFlow(this.getFlow()-temp);
       return temp;
      

      }

    }
    /**

    • 超人套餐

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class SuperPackage extends ServicePackage implements CallServixe,SendService,NetService{
      public int talkTime;//通话时长
      public int smsCount;//短信条数
      public int flow;//流量

      public SuperPackage() {
      this.talkTime = 200;
      this.smsCount = 50;
      this.flow = 1*1024;
      super.price=78;
      }

      public int getFlow() {
      return flow;
      }

      public void setFlow(int flow) {
      this.flow = flow;
      }

      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 shownlfo() {
      // TODO Auto-generated method stub
      super.shownlfo();
      System.out.println(“超人套餐:通话时长为” + this.talkTime + “分钟/月,”
      + “短信条数为”+this.smsCount
      + “条/月,上网流量为:”+this.flow/1024 +“GB/月。”
      );
      }

      @Override
      //通话方法 minCount 通话时长 MobileCard 超出套餐内的通话时长需要消费那张卡的余额
      public int call(int minCount, MobileCard card) throws Exception {
      int temp = minCount;
      for (int i = 0; i < minCount; i++) {
      if (this.talkTime - card.getRealTalkTime() >= 1) {
      //第一种情况:套餐剩余通话时长可以支持1分钟通话
      card.setRealTalkTime(card.getRealTalkTime() +1); //实际通话时长加1

       	}else if (card.getMoney() >=0.2) {
       		//第二种情况: 套餐通话时长已用完,账户余额可以支付1分钟通话,使用账户余额支付
       		card.setRealTalkTime(card.getRealTalkTime() +1);//实际通话时长加1 
       		//账户余额消费0.2元(一分钟额外电话)
       		card.setMoney(Common.sub(card.getMoney(), 0.2));
       		card.setConsumAmount(card.getConsumAmount() + 0.2);
       	} else {
       		temp = i;
       		throw new Exception("本次已通话" +i+"分钟,您的余额不足,请充值后在使用!");
       		
       	}
       }
       this.setTalkTime(this.getTalkTime()-temp);
       return temp;
      

      }

      @Override
      //count发送短信条数 MobileCard 超出后的收费
      public int send(int count, MobileCard card) throws Exception{
      int temp = count;
      for (int i = 0; i < count; i++) {
      if (this.smsCount- card.getRealSMSCount() >= 1) {
      //第一种情况:套餐剩余通话时长可以支持1分钟通话
      card.setRealSMSCount(card.getRealSMSCount() +1); //实际短信条数加1

       	}else if (card.getMoney() >=0.1) {
       		//第二种情况: 套餐通话时长已用完,账户余额可以支付1条短信,使用账户余额支付
       		card.setRealSMSCount(card.getRealSMSCount() +1);//实际短信条数加1
       		//账户余额消费0.1元(一条额外短信)
       		card.setMoney(Common.sub(card.getMoney(), 0.1));
       		card.setConsumAmount(card.getConsumAmount() + 0.1);
       	} else {
       		temp = i;
       		throw new Exception("本次已发短信" +i+"条,您的余额不足,请充值后在使用!");
       		
       	}
       }
       this.setSmsCount(this.getSmsCount()-temp);
       return temp;
      

      }

      @Override
      //flaw上网流量大小 MobileCard 超出流量后的收费
      public int netPlay(int flaw, MobileCard card) throws Exception {
      int temp = flaw;
      for (int i = 0; i < flaw; i++) {
      if (this.flow- card.getRealFlow() >= 1) {
      //第一种情况:套餐剩余通话时长可以支持1分钟通话
      card.setRealFlow(card.getRealFlow() +1); //实际通话时长加1

       	}else if (card.getMoney() >=0.1) {
       		//第二种情况: 套餐通话时长已用完,账户余额可以支付1分钟通话,使用账户余额支付
       		card.setRealFlow(card.getRealFlow() +1);//实际通话时长加1 
       		//账户余额消费0.1元(一分钟额外电话)
       		card.setMoney(Common.sub(card.getMoney(), 0.1));
       		card.setConsumAmount(card.getConsumAmount() + 0.1);
       	} else {
       		temp = i;
       		throw new Exception("本次已用流量" +i+"M,您的余额不足,请充值后在使用!");
       		
       	}
       }
       this.setFlow(this.getFlow()-temp);
       return temp;
      

      }

    }
    /**

    • 话痨套餐

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class TalkPackage extends ServicePackage implements CallServixe,SendService{
      public int talkTime;//通话时长
      public int smsCount;//短信条数

      public TalkPackage() {
      this.talkTime = 500;
      this.smsCount = 30;
      super.price = 58;
      }

      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 shownlfo() {
      // TODO Auto-generated method stub
      super.shownlfo();
      System.out.println(“话痨套餐:通话时长为” + this.talkTime + “分钟/月,”
      + “短信条数为”+this.smsCount
      + “条/月。”
      );
      }

      @Override
      //count发送短信条数 MobileCard 超出后的收费
      public int send(int count, MobileCard card) throws Exception{
      int temp = count;
      for (int i = 0; i < count; i++) {
      if (this.smsCount- card.getRealSMSCount() >= 1) {
      //第一种情况:套餐剩余通话时长可以支持1分钟通话
      card.setRealSMSCount(card.getRealSMSCount() +1); //实际短信条数加1

       	}else if (card.getMoney() >=0.1) {
       		//第二种情况: 套餐通话时长已用完,账户余额可以支付1条短信,使用账户余额支付
       		card.setRealSMSCount(card.getRealSMSCount() +1);//实际短信条数加1
       		//账户余额消费0.1元(一条额外短信)
       		card.setMoney(Common.sub(card.getMoney(), 0.1));
       		card.setConsumAmount(card.getConsumAmount() + 0.1);
       	} else {
       		temp = i;
       		throw new Exception("本次已发短信" +i+"条,您的余额不足,请充值后在使用!");
       		
       	}
       }
       this.setSmsCount(this.getSmsCount()-temp);
       return temp;
      

      }

      @Override
      //通话方法 minCount 通话时长 MobileCard 超出套餐内的通话时长需要消费那张卡的余额
      public int call(int minCount, MobileCard card) throws Exception{
      int temp = minCount;
      for (int i = 0; i < minCount; i++) {
      if (this.talkTime - card.getRealTalkTime() >= 1) {
      //第一种情况:套餐剩余通话时长可以支持1分钟通话
      card.setRealTalkTime(card.getRealTalkTime() +1); //实际通话时长加1

       	}else if (card.getMoney() >=0.2) {
       		//第二种情况: 套餐通话时长已用完,账户余额可以支付1分钟通话,使用账户余额支付
       		card.setRealTalkTime(card.getRealTalkTime() +1);//实际通话时长加1 
       		//账户余额消费0.2元(一分钟额外电话)
       		card.setMoney(Common.sub(card.getMoney(), 0.2));
       		card.setConsumAmount(card.getConsumAmount() + 0.2);
       	} else {
       		temp = i;
       		throw new Exception("本次已通话" +i+"分钟,您的余额不足,请充值后在使用!");
       		
       	}
       }
       this.setTalkTime(this.getTalkTime()-temp);
       return temp;
      

      }

    }
    /**

    • 使用场景

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class Scene {
      public String type;//场景类型
      public int data ;//场景消费数据
      public String description;//场景描述

      public Scene() {
      super();
      }
      public Scene(String type, int data, String description) {
      super();
      this.type = type;
      this.data = data;
      this.description = description;
      }
      public String getType() {
      return type;
      }
      public void setType(String type) {
      this.type = type;
      }
      public int getData() {
      return data;
      }
      public void setData(int data) {

       this.data = data;
      

      }
      public String getDescription() {

       return description;
      

      }
      public void setDescription(String description) {

       this.description = description;
      

      }

    }
    /**

    • 抽取得公有属性和方法的接口 )品牌套餐类 父类

    • @author Chen HuiHong

    • @author 2020年6月6日{time}

    • @Tel 18073799961
      */
      public class ServicePackage {
      public double price;//套餐月资费

      public double getPrice() {
      return price;
      }

      public ServicePackage() {
      super();
      }

      public void shownlfo() {//显示信息

      }

    }

    运行效果为
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    2
    *可选者卡号
    1.13998648298 2.13951284793 3.13967113639
    4.13994561375 5.13964815529 6.13994190607
    7.13954211280 8.13972749893 9.13916332613
    请选择卡号(输入1~9的序号)
    2
    1.话痨套餐 2.网虫套餐 3.超人套餐 请选择序号2
    请输入姓名:橙橙
    请输入密码:123456
    请输入预存话费金额:
    100
    账户余额:100.0
    注册成功:
    卡号:13967113639用户名:橙橙,当前余额:32.0
    网虫套餐:上网流量为:3GB/月。
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    3
    *使用橙橙
    请输入手机号:13967113639
    上网,晚上手机在线看亮剑,看得过瘾,使用流量2GB,剩下的日子干瞪眼~~
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    5
    *资费说明
    品牌套餐 话痨套餐 网虫套餐 超人套餐
    通话时长(分钟) 500mim 200mim
    上网流量(GB) 3GB 1GB
    超出通话:0.2元/分钟
    超出短信:0.1元/条
    超出流量:0.1元/M
    短信条数(条) 30条 50条
    资费(元/月) 58 68 78
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    1
    *用户登录
    请输入手机号:13967113639
    请输入密码:123456
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    1
    *本月账单查询

    您的卡号:13967113639
    套餐资费:68.0
    合计==:68.00.0
    账户余额:32.0

    您的卡号:13967113639单月账单套餐资费:68.0元
    合计:.0元 账户余额:32.0元
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    2
    套餐余量查询
    您的卡号:13967113639
    上网流量:1,GB
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    3
    打印消费详单
    我的标记
    消费记录打印完毕
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    我的标记2
    4
    套餐变更
    请输入要变更的套餐类型:1.话痨套餐 2.网虫套餐 3.超人套餐 请选择序号3
    余额不足,请充值
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    123
    谢谢使用

    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    4
    *话费充值
    请输入手机号:13967113639
    请输入充值金额:1000
    账户余额:1032.0
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    3
    *使用橙橙
    请输入手机号:13967113639
    上网 ,和女友微信视屏聊天,使用流量1GB
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    1
    *用户登录
    请输入手机号:13967113639
    请输入密码:123456
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    4
    *套餐变更
    请输入要变更的套餐类型:1.话痨套餐 2.网虫套餐 3.超人套餐 请选择序号3
    套餐更换完成
    超人套餐:通话时长为200分钟/月,短信条数为50条/月,上网流量为:1GB/月。
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    1
    *本月账单查询

    您的卡号:13967113639
    套餐资费:78.0
    合计==:78.0102.39999999999846
    账户余额:851.5999999999858

    您的卡号:13967113639单月账单套餐资费:78.0元
    合计:102.4元 账户余额:851.6元
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    2
    套餐余量查询
    您的卡号:13967113639
    通话时长:200分钟
    短信条数:50条
    上网流量:1,GB
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    123
    谢谢使用
    **
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    3
    *使用橙橙
    请输入手机号:13967113639
    短信 ,参与环境保护实施方案问卷调查,发送短信5条
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    3
    *使用橙橙
    请输入手机号:13967113639
    短信 ,通知朋友换手机,发送短信50条
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    1
    *用户登录
    请输入手机号:13967113639
    请输入密码:123465
    **欢迎使用橙橙 移动业务大厅
    1.用户登录 2.用户注册 3.使用橙橙 4.话费充值 5.资费说明 6.退出系统
    请选择–
    1
    *用户登录
    请输入手机号:13967113639
    请输入密码:123456
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)
    5
    *办理退网
    ====账号删除
    账户可退余额为:850.5999999999856
    嗖嗖移动用户菜单
    1.本月账单查询 2.套餐余量查询 3.打印消费详单 4.套餐变跟 5.办理退网 请输入(1~5选择功能,其他键返回上一级)

    展开全文
  • 基于java嗖嗖移动业务大厅

    千次阅读 2020-11-16 10:26:43
    //二级菜单 do { System.out.println("*********欢迎使用嗖嗖移动业务大厅********"); System.out.println("1.用户登录"); System.out.println("2.用户注册"); System.out.println("3.使用嗖嗖"); ...

    第一次写的近千行的代码,记录一下
    欢迎大家一起交流学习,
    如果有疑惑的话,欢迎私信互相交流!
    案例覆盖的技能点
    1.封装,继承,多态,接口的使用。
    2.异常处理的合理运用。
    3.集合框架存储数据。
    4.I/O操作及序列化对文件的读写。

    源码:
    接口
    package sousouMobileservices;
    public interface CallService {
    public int call(int minCount,MobileCard card) throws Exception;
    }

    package sousouMobileservices;
    public interface NetService {
    public int netPlay(int flow,MobileCard card) throws Exception;
    }

    package sousouMobileservices;
    public interface SendService {
    public int send( int count,MobileCard card) throws Exception;
    }

    父类
    package sousouMobileservices;

    import java.io.Serializable;

    public abstract class ServicePackage implements Serializable {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    public double price;
    public abstract void showinfo();

    }

    子类1
    package sousouMobileservices;

    public class TalkPackage extends ServicePackage implements SendService, CallService {
    private int talkTime;
    private int smsCount;
    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;
    }
    
    public TalkPackage(int talktime,int smscount,double price) {
    	this.talkTime = talktime;
    	this.price = price;
    	this.smsCount = smscount;
    }
    
    @Override
    public int call(int minCount, MobileCard card) throws Exception {//计算通话时间
    	TalkPackage talkPackage = (TalkPackage) card.getServicePackage();
    	int time = minCount;
    	for (int i = 0; i < minCount; i++) {
    		//套餐剩余通话时长大于一分钟
    		if (talkPackage.getTalkTime()-card.getRealTalkTime()>0) {
    			
    			card.setRealTalkTime(card.getRealTalkTime()+1);
    		}else if (card.getMoney()>=0.2) {
    			//账户余额大于0.2yuan
    			
    			card.setMoney(card.getMoney()-0.2);
    			card.setConsumAmount(card.getConsumAmount()+0.2);
    		}else {
    			time = i;
    			card.setMoney(time);  //因为抛出异常后,下面的语句不会执行,而返回值为零。所以可以通过setMongey暂存。
    			throw new Exception("本次通话"+time+"分钟,您的余额不足,请充值后再使用");
    		}			
    	}
    	return time;
    }
    
    @Override
    public int send(int count, MobileCard card) throws Exception {//计算发送信息
    	TalkPackage talkPackage = (TalkPackage) card.getServicePackage();
    	int time = count;
    	for (int i = 0; i < count; i++) {
    		if (talkPackage.getSmsCount()-card.getRealSMSCount()>0) {
    			
    			card.setRealSMSCount(card.getRealSMSCount()+1);				
    		}else if (card.getMoney()>=0.1) {
    			
    			card.setMoney(card.getMoney()-0.1);
    			card.setConsumAmount(card.getConsumAmount()+0.1);
    		}else {
    			time = i;
    			card.setMoney(time);
    			throw new Exception("本次发信息"+time+"条,您的余额不足,请充值后使用");
    		}			
    	}
    	return time;
    
    }
    
    @Override
    public void showinfo() {
    	System.out.println("话痨套餐:通话时长为500分钟/月,短信条数为30条/ 月");
    	
    }
    

    }

    子类2.
    package sousouMobileservices;

    public class SuperPackage extends ServicePackage implements CallService, SendService, NetService {
    private int talkTime; //通话时长
    private int smsCount;//短信条数
    private int flow; // 流浪
    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;
    }
    
    public int getFlow() {
    	return flow;
    }
    
    public void setFlow(int flow) {
    	this.flow = flow;
    }
    
    public SuperPackage(int talktime,int smscount, int flow, double price) {
    	 this.talkTime = talktime;
    		this.price = price;
    		this.smsCount = smscount;
    		this.flow = flow;
    	
    }
    
    @Override
    public int netPlay(int flow, MobileCard card) throws Exception {
    	SuperPackage superPackage = (SuperPackage) card.getServicePackage();
    	int spend = flow*1024;
    	for (int i = 0; i < flow*1024; i++) {
    		if ((superPackage.getFlow())*1024-card.getRealFlow()>0) {
    			
    			card.setRealFlow(card.getRealFlow()+1);				
    		}else if (card.getMoney()>=0.1) {
    			
    			card.setMoney(card.getMoney()-0.1);
    			card.setConsumAmount(card.getConsumAmount()+0.1);
    		}else {
    			spend = i;
    			card.setMoney(spend);
    			throw new Exception("本次上网流量"+spend+"MB,您的余额不足,请充值后使用");
    		}
    		
    	}
    	return spend;
    
    }
    
    @Override
    public int send(int count, MobileCard card) throws Exception {
    	SuperPackage superPackage = (SuperPackage) card.getServicePackage();
    	int time = count;
    	for (int i = 0; i < count; i++) {
    		if (superPackage.getSmsCount()-card.getRealSMSCount()>0) {
    			
    			card.setRealSMSCount(card.getRealSMSCount()+1);				
    		}else if (card.getMoney()>=0.1) {
    			
    			card.setMoney(card.getMoney()-0.1);
    			card.setConsumAmount(card.getConsumAmount()+0.1);
    		}else {
    			time = i;
    			card.setMoney(time);
    			throw new Exception("本次发信息"+time+"条,您的余额不足,请充值后使用");
    		}
    		
    	}
    	return time;
    
    }
    
    @Override
    public int call(int minCount, MobileCard card) throws Exception {
    	SuperPackage superPackage = (SuperPackage) card.getServicePackage();
    	int time = minCount;
    	for (int i = 0; i < minCount; i++) {
    		//套餐剩余通话时长大于一分钟
    		if (superPackage.getTalkTime()-card.getRealTalkTime()>0) {
    			
    			card.setRealTalkTime(card.getRealTalkTime()+1);
    		}else if (card.getMoney()>=0.2) {
    			//账户余额大于0.2yuan
    			
    			card.setMoney(card.getMoney()-0.2);
    			card.setConsumAmount(card.getConsumAmount()+0.2);
    		}else {
    			time = i;
    			card.setMoney(time);
    			throw new Exception("本次通话"+time+"分钟,您的余额不足,请充值后再使用");
    		}
    		
    	}
    		return time;
    }
    
    @Override
    public void showinfo() {
    	
    	System.out.println("超人套餐:通话时长为200分钟/月,短信条数为50条/ 月,上网流量1GB/月");
    
    }
    

    }
    子类3
    package sousouMobileservices;
    //网虫套餐
    public class NetPackage extends ServicePackage implements NetService {
    private int flow ;
    public int getFlow() {
    return flow;
    }

    public void setFlow(int flow) {
    	this.flow = flow;
    }
    
    public NetPackage(int flow,double price) {
    	this.price = price;
    	this.flow = flow;
    }
    
    @Override
    public int netPlay(int flow, MobileCard card) throws Exception {
    	NetPackage netPackage = (NetPackage) card.getServicePackage();
    	int spend = flow*1024;
    	;
    	for (int i = 0; i < flow*1024; i++) {
    		if ((netPackage.getFlow())*1024-card.getRealFlow()>0) {
    			
    			card.setRealFlow(card.getRealFlow()+1);				
    		}else if (card.getMoney()>=0.1) {
    			
    			card.setMoney(card.getMoney()-0.1);
    			card.setConsumAmount(card.getConsumAmount()+0.1);
    		}else {
    			spend = i;
    			card.setMoney(spend);
    			throw new Exception("本次上网话费"+spend+"MB,您的余额不足,请充值后使用");
    		}
    		
    	}
    	return spend;
    
    }
    
    @Override
    public void showinfo() {
    	System.out.println("网虫套餐:上网流量3GB/月");
    
    }
    

    }

    一级菜单(main)
    package sousouMobileservices;

    //import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    //import java.io.OutputStreamWriter;
    import java.util.Scanner;

    //import com.alibaba.fastjson.JSON;

    public class Testmain {

    public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
    	CardUtil cardUtil = new CardUtil();//工具对象
    	SosoMgr sosoMgr = new SosoMgr();  //二级菜单
    		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("6.退出系统");
    			int number;
    			do {                   //验证输入的值是否合法
    				if (input.hasNextInt()) {
    					number  = input.nextInt();
    					if (number<7&&number>=0) {
    						break;							
    					}
    					else {
    						System.out.println("您的输入有误,请重新输入");
    						input.next();							
    					}					
    				}
    				else {
    					System.out.println("您的输入有误,请重新输入");
    					input.next();
    				}
    			} while (true);
    			
    			switch (number) {
    				  case 1://登录功能
    					  System.out.println("请输入您的卡号");
    					  String numbers = input.next();
    					  System.out.println("请输入您的密码");
    					  String passWord = input.next();
    					  if (cardUtil.isExistCard(numbers, passWord)) {
    						  sosoMgr.cardMenu(cardUtil,numbers);
    						  break;
    					}else {
    						break;
    					}
    				
    						//break;
                	  case 2:
                		  MobileCard card = new MobileCard();
    				cardUtil.addCard(card);
                			break;
    				  case 3://使用嗖嗖
    					  System.out.println("请输入您的卡号");
    					  String numbers1 = input.next();
    					  if (cardUtil.isExistCard(numbers1)) {
    						  cardUtil.useSoso(numbers1);							
    					}
    					  	break;
    				  case 4://充值金额
    					 System.out.println("请输入充值卡号");
    					 String numbers3 = input.next();
    				cardUtil.chargeMoney(numbers3);
    						break;
    				  case 5://资费说明
    				cardUtil.showDescription();
    						break;
    						
    				  case 6:
    					  ObjectOutputStream objectOutputStream = null;
    				try {
    					objectOutputStream = new ObjectOutputStream(new FileOutputStream("F:\\课工场培训\\java学习\\workspace\\sousouMobileservices\\src\\sousouMobileservices\\message.txt"));
    				objectOutputStream.writeObject(cardUtil.cards);
    				objectOutputStream.flush();
    				} catch (FileNotFoundException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}finally {
    					if (objectOutputStream!=null) {
    						try {
    							objectOutputStream.close();
    						} catch (Exception e2) {
    							// TODO: handle exception
    						}
    					}
    				}	 
    				// String map = JSON.toJSONString( cardUtil.cards, true)						  
    					  System.out.println("欢迎再次使用,再见!");
    						System.exit(0);
    						break;
    			default:
    				break;
    			}
    			//input.close();
    		} while (true);
    		
    }
    

    }

    二级菜单
    package sousouMobileservices;

    import java.util.Scanner;

    public class SosoMgr {
    CardUtil cardUtil;
    public void cardMenu(CardUtil cardUtil,String numbers) {
    this.cardUtil = cardUtil;
    boolean isExit = true;
    Scanner input = new Scanner(System.in);
    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选择功能,其他键返回上一级:)”);
    String number =input.next();

    				switch (number) {
    					  case "1": // 查询本月账单
    					cardUtil.showAmountDetail(numbers);
    							break;
                    	  case "2"://套餐余量查询
    					cardUtil.showRemainDetail(numbers);
                    			break;
    					  case "3"://打印消费详单
    					cardUtil.printConsumInfo(numbers);	
    						  	break;
    					  case "4"://套餐变更
    					cardUtil.changingPack(numbers);
    							break;
    					  case "5":// 办理退网							  
    					cardUtil.delCard(numbers);
    						isExit = false;
    							break;
    				default :
    					isExit = false;
    				    break;
    				}
    				
    			} while (isExit);
    	
    		//input.close();
    	}
    

    }

    工具类
    package sousouMobileservices;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.ObjectInputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.text.DecimalFormat;
    //import java.nio.Buffer;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    //import java.util.List;
    import java.util.Map;
    import java.util.Random;
    import java.util.Scanner;

    //import javax.activation.MailcapCommandMap;

    //import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;

    public class CardUtil {
    public final static ServicePackage[] serive = new ServicePackage[3];//初始化套餐信息
    static {
    serive[0] = new TalkPackage(500,30,58);
    serive[1] = new SuperPackage(200, 50, 1, 78);
    serive[2] = new NetPackage(3, 68);

    }
    
    public final static Scene []scene = new Scene[6];   //初始化场景信息
    static {
    	scene[0] = new Scene("通话", 90, "问候客户,客户如此难缠,通话90分钟");
    	scene[1] = new Scene("通话",30 ,"询问妈妈身体状况,本地通话30分钟" );
    	scene[2] = new Scene("短信",5 ,"参与环境保护实施方案问卷调查,发送短信5条" );
    	scene[3] = new Scene("短信",50 ,"通知朋友手机换号,发送信息50条");
    	scene[4] = new Scene("上网",1 ,"和女友微信视频聊天,使用流量1GB");
    	scene[5] = new Scene("上网", 2,"晚上手机在线看韩剧,不留神睡着了!使用流量2GB");
    }
       // public ArrayList<ConsumInfo> consumInfos;
    	public Map<String , MobileCard> cards = new HashMap<String, MobileCard>();          //已注册的嗖嗖移动用户列表
    
    	public ArrayList<ConsumInfo>arrayList = new ArrayList<ConsumInfo>();
    	
    	public Map<String, ArrayList<ConsumInfo>> consumInfos =  new HashMap<String, ArrayList<ConsumInfo>>();//所有卡号的消费记录列表
    	
    	Scanner input = new Scanner(System.in);
    	@SuppressWarnings("unchecked")
    	public CardUtil() {//构造函数
    		// TODO Auto-generated constructor stub
    		ObjectInputStream objectInputStream =null;
    		try {
    			objectInputStream = new ObjectInputStream(new FileInputStream("F:\\课工场培训\\java学习\\workspace\\sousouMobileservices\\src\\sousouMobileservices\\message.txt"));
    		cards = (Map<String, MobileCard>) objectInputStream.readObject();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally {
    			if (objectInputStream!=null) {
    				try {
    					objectInputStream.close();
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				
    			}
    		}
    		
    	}
    	
    	public static String dataFormat(double data) {   //double类型格式装换
    		DecimalFormat format = new DecimalFormat("#.0");
    		return format.format(data);
    	}
    

    // public void initScene() {
    // }

    // public Map<String, MobileCard> test() { //测试用
    // MobileCard aCard = new MobileCard();
    // aCard.setCardNumber(“123”);
    // aCard.setPassWord(“123”);
    // aCard.setUserName(“123”);
    // aCard.setServicePackage(serive[1]);
    // aCard.setConsumAmount(12);
    // aCard.setMoney(10);
    // cards.put(“123”, aCard);
    // return cards;
    // }
    public boolean isExistCard(String number,String passWord) {//根据卡号密码验证卡是否注册
    //cards = test();//测试用
    if (cards.containsKey(number)) {
    if (passWord.equals(cards.get(number).getPassWord())) {
    System.out.println(“登录成功”);
    return true;
    }else {
    System.out.println(“密码错误”);
    return false;
    }
    }
    else {
    System.out.println(“手机卡号错误”);
    return false;
    }
    }

    	public boolean isExistCard(String number) {//根据卡号验证卡是否注册
    		//cards = test();//测试用
    		if (cards.containsKey(number)) {
    			return true;
    		}else {
    			System.out.println("该手机号不存在");
    			return false;
    		}
    	}
    	
    	
    	public String creatNumber() {//生成随机卡号
    		System.out.println("*******可选择的卡号***********");
    		Random random = new Random();
    		String [] number = new String[9];
    		boolean isExist = true;     //标志位
    		int i = 1;
    		do {			
    		do { 
    		 int b  = (random.nextInt(90000000)+10000000);//产生一个随机数
    		 number[i-1] = "139"+b;                       //利用字符串拼接产生一个号码
    		if (!cards.containsKey(number[i-1])) {
    			
    			System.out.print(i+"."+number[i-1]+"\t");
    			isExist = false;				
    			if (i%3==0) {
    				System.out.println();
    			}
    			i++;
    		}	else {
    			isExist = true;
    		}			
    		} while (isExist);
    		} while (i!=10);
    		System.out.println("请选择卡号(1-9)");
    		int is;
    		do {
    			if (input.hasNextInt()) {
    				is = input.nextInt();
    				break;
    			}
    			else {
    				System.out.println("输入有误,请重新输入");
    				input.next();
    			}
    		} while (true);
    		return number[is-1];
    	}
    

    // public String[] getNewNumbers(int count) {//生成指定个数的卡号列表
    // return “a”;
    // }
    public void addCard(MobileCard card) {//注册新卡
    String number = creatNumber(); //选择的卡号
    System.out.println(“1.话痨套餐”+"\t"+“2.超人套餐”+"\t"+“3.网虫套餐,”+"\t"+“请选择套餐(输入序号):”);
    int order;
    do {
    if (input.hasNextInt()) {
    order = input.nextInt();
    if (order<4&&order>0) {
    break;
    }else {
    System.out.println(“没有该种套餐,请重新输入”);
    }
    }else {
    System.out.println(“输入错误指令,请重新输入”);
    input.next();
    }
    } while (true);
    card.setServicePackage(serive[order-1]);//选择对应套餐
    //card.getServicePackage().showinfo();
    System.out.println(“请输入姓名”);
    String name = input.next();
    System.out.println(“请输入密码”);
    String passwod = input.next();
    System.out.println(“请输入预存话费金额”);
    double money;
    do {
    do {
    if (input.hasNextDouble()) {
    money = input.nextDouble();
    break;
    }
    else {
    System.out.println(“输入有误,请重新输入”);
    input.next();
    }
    } while (true);

    	if (money>=card.getServicePackage().price) {
    		//设置消费金额和账户余额
    		card.setMoney(money-card.getServicePackage().price);
    		card.setConsumAmount(card.getConsumAmount()+card.getServicePackage().price);
    		break;
    	}else {
    		System.out.println("您预存的话费金额不足以支付本月固定套餐资费,请重新充值");
    	}
    	} while (true);
    	//初始化卡号信息
    	card.setCardNumber(number);
    	card.setUserName(name);
    	card.setPassWord(passwod);
    	
    	cards.put(number, card);  //存入集合
    	//显示卡号信息
    	System.out.println("注册成功!");
    	System.out.println("卡号:"+number+" 用户名:"+name+"当前余额:"+dataFormat(card.getMoney())+"元");
    	card.getServicePackage().showinfo();
    	
    	}
    	
    	public void showRemainDetail(String number) {//套餐余量查询
    		//cards = test();//测试用
    		int remainTalkTime;
    		int remainSmsCount;
    		int remainFlow;
    		 ServicePackage servicePackage = cards.get(number).getServicePackage();		
    			//ServicePackage servicePackage = ServicePackage.class.newInstance();//使用反射获取相应的套餐类
    		 System.out.println("***********套餐余量查询***********");
    		 System.out.println("您的卡号是 "+number+"套餐内剩余");
    			if (servicePackage instanceof TalkPackage) {
    				TalkPackage talkPackage =(TalkPackage) servicePackage;
    				remainSmsCount = talkPackage.getSmsCount()>cards.get(number).getRealSMSCount()?talkPackage.getSmsCount()-cards.get(number).getRealSMSCount():0;
    				remainTalkTime = talkPackage.getTalkTime()>cards.get(number).getRealTalkTime()?talkPackage.getTalkTime()-cards.get(number).getRealTalkTime():0;
    				System.out.println("通话时长"+remainTalkTime+"分钟");
    				System.out.println("短信条数"+remainSmsCount+"条");
    			}else if (servicePackage instanceof SuperPackage) {
    				SuperPackage superPackage = (SuperPackage) servicePackage;
    				remainSmsCount = superPackage.getSmsCount()>cards.get(number).getRealSMSCount()?superPackage.getSmsCount()-cards.get(number).getRealSMSCount():0;
    				remainTalkTime = superPackage.getTalkTime()>cards.get(number).getRealTalkTime()?superPackage.getTalkTime()-cards.get(number).getRealTalkTime():0;
    				remainFlow = superPackage.getFlow()>cards.get(number).getRealFlow()?superPackage.getFlow()-cards.get(number).getRealFlow():0;
    				System.out.println("通话时长"+remainTalkTime+"分钟");
    				System.out.println("短信条数"+remainSmsCount+"条");
    				System.out.println("上网流量"+remainFlow+"GB");
    			} else if (servicePackage instanceof NetPackage) {
    				NetPackage netPackage = (NetPackage) servicePackage;
    				remainFlow = netPackage.getFlow()>cards.get(number).getRealFlow()?netPackage.getFlow()-cards.get(number).getRealFlow():0;
    				System.out.println("上网流量"+remainFlow);
    			}		
    	}
    	
    	public void showAmountDetail(String number) {//本月账单查询
    		cards.get(number).showMeg();
    	}
    	
    	public void addConsumInfo(String number,ConsumInfo info) {//添加指定卡号的消费记录
    		//cards = test();//测试用
    		if (consumInfos.containsKey(number)) {
    			consumInfos.get(number).add(info);
    			System.out.println("成功添加一条消费记录");
    			}else {
    				arrayList.add(info);
    				consumInfos.put(number, arrayList);
    				System.out.println("不存在此卡的消费记录,已添加一条消费记录");
    			}
    	}
    	
    	public void useSoso(String number) {//使用嗖嗖
    		//cards = test();//测试用
    		ServicePackage servicePackage = cards.get(number).getServicePackage();
    		TalkPackage talkPackage;
    		SuperPackage superPackage ;
    		//NetPackage netPackage;
    		
    		Random random = new Random();
    		int a;
    		int use = 0;
    		
    		do {
    		a = random.nextInt(6);
    		switch (a) {
    		case 0:
    					
    		case 1:
    			//电话
    			if (servicePackage instanceof TalkPackage) {
    			 talkPackage = (TalkPackage) servicePackage;
    			 System.out.println(scene[a].getDescription());
    			 try {
    				use = talkPackage.call(scene[a].getData(), cards.get(number));
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}//调用call方法
    			 if (use==0) {
    				 use = (int)cards.get(number).getMoney();
    				 cards.get(number).setMoney(0);
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    				
    			}else {
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    			}			
    		}else if(servicePackage instanceof SuperPackage) {
    			 superPackage = (SuperPackage) servicePackage;
    			 System.out.println(scene[a].getDescription());
    			 try {
    				use = superPackage.call(scene[a].getData(), cards.get(number));
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			
    			 //addConsumInfo(number,scene[a].getType(),use);
    			 if (use==0) {
    				 use = (int)cards.get(number).getMoney();
    				 cards.get(number).setMoney(0);
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    				
    			}else {
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    			}	
    			 
    			 break;
    		}
    		else {
    			//该卡套餐不支持通话功能,重新生成随机数。
    			continue;
    		}
    			
    			break;
            case 2:
    			
    			
            case 3:     //短信
            	if (servicePackage instanceof TalkPackage) {
    			 talkPackage = (TalkPackage) servicePackage;
    			 System.out.println(scene[a].getDescription());
    			 try {
    				use = talkPackage.send(scene[a].getData(), cards.get(number));
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}//调用call方法
    			 if (use==0) {
    				 use = (int)cards.get(number).getMoney();
    				 cards.get(number).setMoney(0);
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    				
    			}else {
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    			}	
    		}else if(servicePackage instanceof SuperPackage) {
    			 superPackage = (SuperPackage) servicePackage;
    			 System.out.println(scene[a].getDescription());
    			 try {
    				use = superPackage.send(scene[a].getData(), cards.get(number));
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			 //addConsumInfo(number,scene[a].getType(),use);
    			 if (use==0) {
    				 use = (int)cards.get(number).getMoney();
    				 cards.get(number).setMoney(0);
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    				
    			}else {
    				 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    			}	
    		}
    		else {
    			//该卡套餐不支持通话功能,重新生成随机数。
    			continue;
    		}
    			break;
    		case 4:
    			
    			
    		case 5://上网
    			if (servicePackage instanceof NetPackage) {
    				NetPackage netPackage2 = (NetPackage) servicePackage;
    				System.out.println(scene[a].getDescription());
    				try {
    					use = netPackage2.netPlay(scene[a].getData(),cards.get(number));
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    				 if (use==0) {
    					 use = (int)cards.get(number).getMoney();
    					 cards.get(number).setMoney(0);
    					 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    					
    				}else {
    					 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    				}	
    			}else if(servicePackage instanceof SuperPackage){
    	   				 superPackage = (SuperPackage) servicePackage;
    	   				 System.out.println(scene[a].getDescription());
    	   				 try {
    	   					use = superPackage.netPlay(scene[a].getData(), cards.get(number));
    	   				} catch (Exception e) {
    	   					// TODO Auto-generated catch block
    	   					e.printStackTrace();
    	   				} 
    	   		
    	   				 //addConsumInfo(number,scene[a].getType(),use);
    	   				 if (use==0) {
    						 use = (int)cards.get(number).getMoney();
    						 cards.get(number).setMoney(0);
    						 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    						
    					}else {
    						 addConsumInfo(number, new ConsumInfo(number, scene[a].getType(),use));
    					}	
    	   			}
    	   			else {
    	   				//该卡套餐不支持通话功能,重新生成随机数。
    	   				continue;
    	   			}
    			}				
    			break;						
    		}while(true);
    	}
    
    	public void printConsumInfo(String number) {//输出指定卡号消费记录
    		OutputStream outputStream;
    		BufferedWriter bufferedWriter ;
    		try {
    
    		 	if (consumInfos.containsKey(number)) {
    		 		int i =0;
    		 		if (consumInfos.get(number)!=null) {
    		 			 outputStream = new FileOutputStream("src/sousouMobileservices/"+number+"消费记录.txt");
    				     bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
    					Iterator<ConsumInfo>iterator = consumInfos.get(number).iterator();
    					while (iterator.hasNext()) {
    						ConsumInfo consumInfo = (ConsumInfo) iterator.next();
    						i++;
    						if (consumInfo.getType().equals("上网")) {
    							bufferedWriter.write(i+"."+consumInfo.getType()+consumInfo.getConsumData()+"MB");
    							bufferedWriter.write("\n");
    							bufferedWriter.flush();	
    						}else if (consumInfo.getType().equals("短信")) {
    							bufferedWriter.write(i+"."+consumInfo.getType()+consumInfo.getConsumData()+"条");
    							bufferedWriter.write("\n");
    							bufferedWriter.flush();	
    						}else {
    							bufferedWriter.write(i+"."+consumInfo.getType()+consumInfo.getConsumData()+"分钟");
    							bufferedWriter.write("\n");
    							bufferedWriter.flush();	
    						}						
    					}
    					System.out.println("消费记录打印完毕!");
    					bufferedWriter.close();
    					outputStream.close();
    				}
    		 		else {
    		 			System.out.println("对不起,不存在此号码的消费记录,不能打印!");
    				}
    			}else {
    				System.out.println("对不起,不存在此号码,不能打印!");
    			}
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    			
    	public void showDescription() {//资费说明
    		try {
    			InputStream inputStream = new FileInputStream("F:\\课工场培训\\java学习\\workspace\\sousouMobileservices\\src\\Service.txt");
    			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
    			String line = bufferedReader.readLine();
    			while (line!=null) {
    				System.out.println(line);
    				line = bufferedReader.readLine();
    			}
    			bufferedReader.close();
    			inputStream.close();
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    	
    	public void changingPack(String number) {//套餐变更
    		System.out.println("********套餐变更*********");
    		System.out.println("1.话痨套餐"+"\t"+"2.超人套餐"+"\t"+"3.网虫套餐,"+"\t"+"请选择套餐(输入序号):");
    		int digit ;
    		do {
    			if (input.hasNextInt()) {
    				digit = input.nextInt();
    				if (digit<4&&digit>0) {
    					break;
    				}else {
    					System.out.println("没有该种套餐,请重新输入");
    				}
    			}else {
    				System.out.println("输入错误指令,请重新输入");
    				input.next();
    			}
    		} while (true);
    		if (digit==1) {
    			if (cards.get(number).getServicePackage()instanceof TalkPackage) {
    				System.out.println("对不起,您已经是该卡套餐用户,无需更换!");
    			}else if (cards.get(number).getMoney()<58) {
    				System.out.println("对不起,您的余额不足以支付新套餐本月资费,请充值后在办理更换套餐业务!");
    			}else {
    				cards.get(number).setRealFlow(0);
    				cards.get(number).setRealTalkTime(0);
    				cards.get(number).setRealSMSCount(0);
    				cards.get(number).setServicePackage(serive[digit-1]);
    				cards.get(number).setMoney(cards.get(number).getMoney()-serive[digit-1].price);
    				cards.get(number).setConsumAmount(serive[digit-1].price);
    				System.out.println("套餐变更成功! 话痨套餐:通话时长500分钟/ 月,短信条数为30条/月,资费为58.0/月.");
    			}
    			
    		}else if (digit==2) {
    			if (cards.get(number).getServicePackage()instanceof SuperPackage) {
    				System.out.println("对不起,您已经是该卡套餐用户,无需更换!");
    			}else if (cards.get(number).getMoney()<78) {
    				System.out.println("对不起,您的余额不足以支付新套餐本月资费,请充值后在办理更换套餐业务!");
    			}else {
    				cards.get(number).setRealFlow(0);
    				cards.get(number).setRealTalkTime(0);
    				cards.get(number).setRealSMSCount(0);
    				cards.get(number).setServicePackage(serive[digit-1]);
    				cards.get(number).setMoney(cards.get(number).getMoney()-serive[digit-1].price);
    				cards.get(number).setConsumAmount(serive[digit-1].price);
    				System.out.println("套餐变更成功! 超人套餐:通话时长200分钟/ 月,上网流量1GB/月,短信条数为50条/月,资费为78.0/月.");
    			}	
    		}else {
    			if (cards.get(number).getServicePackage()instanceof NetPackage) {
    				System.out.println("对不起,您已经是该卡套餐用户,无需更换!");
    			}else if (cards.get(number).getMoney()<68) {
    				System.out.println("对不起,您的余额不足以支付新套餐本月资费,请充值后在办理更换套餐业务!");
    			}else {
    				cards.get(number).setRealFlow(0);
    				cards.get(number).setRealTalkTime(0);
    				cards.get(number).setRealSMSCount(0);
    				cards.get(number).setServicePackage(serive[digit-1]);
    				cards.get(number).setMoney(cards.get(number).getMoney()-serive[digit-1].price);
    				cards.get(number).setConsumAmount(serive[digit-1].price);
    				System.out.println("套餐变更成功! 网虫套餐:上网流量3GB/月,资费为68.0/月.");
    		}
    	}
    	}
    	public void chargeMoney(String number) {//话费充值
    		if (cards.containsKey(number)) {
    			System.out.println("请输入充值金额");
    			double money ;
    			do {
    				do {
    					if (input.hasNextDouble()) {
    						money = input. nextDouble();
    						break;
    					}else {
    						System.out.println("输入无效字符,请重新输入");
    						input.next();
    					}
    				} while (true);
    				//money = input.nextDouble();
    				if (money>=50) {
    					cards.get(number).setMoney(cards.get(number).getMoney()+money);
    					System.out.println("充值成功,当前话费余额为"+dataFormat(cards.get(number).getMoney())+"元");
    					break;
    				}else {
    					System.out.println("最少充值50元,请重新充值");
    				}
    			} while (true);		
    		}
    	}	
    	public void delCard(String number) {
    		System.out.println("办理退网");
    		//FileReader对象. fr.closefile.delete()。
    		File file = new File("src/sousouMobileservices/"+number+"消费记录.txt");
    		if(file.exists())    //删除要退网的为用户的文件
    		{
    			file.delete(); 
    		}
    		cards.remove(number);
    		System.out.println("卡号"+number+"办理退网成功!");
    		System.out.println("谢谢使用");
    		
    	}
    	public Map<String, MobileCard> exit() {
    		return cards;
    	}
    

    }

    package sousouMobileservices;

    public class ConsumInfo {//消费信息
    private String cardNumber;//卡号
    private String type; //消费类型
    private int consumData;// 消费数据
    public ConsumInfo(String cardnumber,String type,int consumdata) {
    this.cardNumber = cardnumber;
    this.type = type;
    this.consumData = consumdata;
    }
    public String getCardNumber() {
    return cardNumber;
    }
    public void setCardNumber(String cardNumber) {
    this.cardNumber = cardNumber;
    }
    public String getType() {
    return type;
    }
    public void setType(String type) {
    this.type = type;
    }
    public int getConsumData() {
    return consumData;
    }
    public void setConsumData(int consumData) {
    this.consumData = consumData;
    }
    }

    package sousouMobileservices;
    //场景
    public class Scene {
    private String type;//套餐内容
    private int data; // 数据量
    private String description;//描述
    public Scene(String type,int data,String description) {
    this.type = type;
    this.data = data;
    this.description = description;
    }
    public String getType() {
    return type;
    }
    public void setType(String type) {
    this.type = type;
    }
    public int getData() {
    return data;
    }
    public void setData(int data) {
    this.data = data;
    }
    public String getDescription() {
    return description;
    }
    public void setDescription(String description) {
    this.description = description;
    }

    	//public double price;
    

    }
    package sousouMobileservices;

    import java.io.Serializable;

    public class MobileCard implements Serializable {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private String cardNumber; //卡号
    private String userName; //用户名
    private String passWord; //密码
    private ServicePackage servicePackage; //套餐
    private double consumAmount; //消费总额
    private double money; //剩余金额
    private int realTalkTime = 0; //当月通话时间
    private int realSMSCount = 0; //当月发送信息条数
    private int realFlow = 0; //当月使用流量
    public String getCardNumber() {
    return cardNumber;
    }
    public void setCardNumber(String cardNumber) {
    this.cardNumber = cardNumber;
    }
    public String getUserName() {
    return userName;
    }
    public void setUserName(String userName) {
    this.userName = userName;
    }
    public String getPassWord() {
    return passWord;
    }
    public void setPassWord(String passWord) {
    this.passWord = passWord;
    }
    public ServicePackage getServicePackage() {
    return servicePackage;
    }
    public void setServicePackage(ServicePackage servicePackage) {
    this.servicePackage = servicePackage;
    }
    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 int getRealFlow() {
    return realFlow;
    }
    public void setRealFlow(int realFlow) {
    this.realFlow = realFlow;
    }
    public void showMeg() {

    		System.out.println("******本月账单查询**********");
    		System.out.println("您的卡号:"+getCardNumber()+",当月账单");
    		System.out.println("套餐资费:"+CardUtil.dataFormat(getServicePackage().price)+"元");
    		System.out.println("合计:"+CardUtil.dataFormat(getConsumAmount())+"元");
    		System.out.println("账户余额:"+CardUtil.dataFormat(getMoney())+"元");
        
    	}
    

    }

    通过项目获得的一些知识点。
    一.double型做除法时,一定要注意除数或者被除数一定要至少有一个为double型!!
    两个double型数据做操作,会有精度丢失 的情况。所以需要用到
    public static String dataFormat(double data) { //double类型格式装换
    DecimalFormat format = new DecimalFormat("#.0");
    return format.format(data);
    }
    二.opearate和romove都用System.in创建了Scanner,当opearate的Scanner还没有关闭,调用了remove,而remove中则是打开Scanner后关闭,这里间接地将System.in也关闭了,因为System.in是个静态流,所以引用其的Scanner对象内都是相同状态的。当操作后返回到opearate,这时再调用nextInt,在System.in已经关闭了情况下,不能读取到任何数据,就会产生 java.util.NoSuchElementException,即使是在两个不同的Scanner对象中调用System.in(两者hash值不一样)。

    三. a)序列化时,只对对象的状态进行保存,而不管对象的方法;
    b)当一个父类实现序列化,子类自动实现序列化,不需要显式实现Serializable接口;
    c)当一个对象的实例变量引用其他对象,序列化该对象时也把引用对象进行序列化;
    d)并非所有的对象都可以序列化

    展开全文
  • 人力资源服务行业最大的...【合作项目】10086移动外呼业务:(4G升级5G套餐升档,流量包,宽带办理续费等)【合作条件】:能组织定点10-15人以上即可,不限制地域,能管理人员;【星楚负责】项目业务,人员培训,员工工...
  • 该项目时基于javafx实现的图形化小demo,实现了一些简单的操作!
  • 嗖嗖移动大厅小项目

    2019-03-22 10:26:03
    在Java小白学过 面向对象设计的思想 并且熟练掌握封装、继承、多态、接口的使用 理解合理运用异常处理的方法 掌握集合框架存储数据 掌握I/O操作实现对文件的读写 之后,可练习此小项目
  • 嗖嗖移动业务大厅源码实例,及供参考~~~~~~~~~~~~~~~~~~~~~~~~~~~有什么不懂:联系微信 dzl-wx
  • java高级特性项目

空空如也

空空如也

1 2 3 4 5
收藏数 97
精华内容 38
关键字:

嗖嗖移动业务大厅