移动soso

package com.baidu.entity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class Init {
	static List<Account> alist = new ArrayList<Account>();
	static List<TalkPackage> Tlist = new ArrayList<TalkPackage>();
	static List<Account> dylist = new ArrayList<Account>();
	static List<NetPackage> blist = new ArrayList<NetPackage>();
	static List<SuperPackage> clist = new ArrayList<SuperPackage>();
	static long[] list = null;
	static int kh;
	static int xh;
	static double sumMoney;

	public void init() throws Exception {
		// 打印
		Scanner sca = new Scanner(System.in);
		String con = "";
		do {

			System.out.println("*************欢迎使用嗖嗖移动业务大厅***************");
			System.out
					.println("1.用户登录   2.用户注册   3.使用嗖嗖   4.话费充值  5.资费说明  6.退出系统");
			System.out.println("请选择:");
			int num = sca.nextInt();
			switch (num) {
			case 1:// 用户登录
				login();
				break;
			case 2:// 用户注册
				cards();
				taocan();
				break;
			case 3: // 使用嗖嗖
				soso();
				break;
			case 4:// 话费充值
				System.out.println("请输入要充值的手机号:");
				long tel = sca.nextLong();
				for (int i = 0; i < alist.size(); i++) {
					Account a = new Account();
					System.out.println("当前话费为:" + alist.get(i).getMoney());
					System.out.println("请输入要充值的金额");
					int money = sca.nextInt();
					sumMoney += money;
					double sum = money + alist.get(i).getMoney();
					alist.get(i).setMoney(sum);
					System.out.println("充值成功!");
					break;
				}
				break;
			case 5:
				File file = new File("D:\\soso.txt");
				FileInputStream fis = new FileInputStream(file);
				InputStreamReader isr = new InputStreamReader(fis);
				BufferedReader br = new BufferedReader(isr);
				String str = "";
				while ((str = br.readLine()) != null) {
					System.out.println(str);
				}
				br.close();
				break;
			case 6:
				System.out.println("成功退出嗖嗖移动业务大厅");
				System.exit(0);
				break;
			}
			System.out.println("是否返回主菜单y\\n");
			con = sca.next();
		} while (con.equals("y"));

	}

	public void cards() {// 号码选择
		System.out.println("*******可选择的卡号*******");
		Random r = new Random();
		list = new long[9];
		for (int i = 0; i < list.length; i++) {
			int a = r.nextInt(9999) + 1000;
			int b = r.nextInt(9999) + 1000;
			int c = 139;
			long card = (long) (c * (Math.pow(10, 8)) + a * 1000 + b);
			list[i] = card;
			System.out.println(i + 1 + "." + list[i]);
		}
		Scanner sca = new Scanner(System.in);
		System.out.println("请选择卡号(输入1~9的序号):");
		kh = sca.nextInt();
		System.out.println("你选择的卡号是:" + list[kh - 1]);
	}

	public void taocan() throws Exception {
		Scanner sca = new Scanner(System.in);
		System.out.println("1.话唠套餐  2.网虫套餐  3.超人套餐\n 请选择套餐(输入序号):");
		int num = sca.nextInt();
		boolean w = alist.isEmpty();// 判段alist是否为空
		switch (num) {
		case 1:
			xh = 1;
			boolean flag = blist.isEmpty();
			boolean fl = clist.isEmpty();
			if (flag == false || fl == false) {
				blist.removeAll(blist);
				clist.removeAll(clist);
				changmeal();
			}
			int price = 58;
			if (w == true) {
				result(price);
			}
			TalkPackage talk = new TalkPackage();
			talk.setMinutes(200);
			talk.setTexts(50);
			Tlist.add(talk);
			// String hl="话唠套餐:通话时长:200分钟 ,短信条数:50条,月资费:58元";
			System.out.println("话唠套餐:通话时长:200分钟 ,短信条数:50条,月资费:58元");
			break;
		case 2:// 网虫套餐
				// String wc="网虫套餐:上网流量:5GB,月资费:68元";
			xh = 2;

			boolean flag1 = Tlist.isEmpty();
			boolean fl1 = clist.isEmpty();
			if (flag1 == false || fl1 == false) {
				Tlist.removeAll(Tlist);
				clist.removeAll(clist);
				changmeal();
			}
			// System.out.println(flag1);
			int price2 = 68;
			int chat = 5000;
			NetPackage net = new NetPackage();
			net.setChat(chat);
			blist.add(net);
			System.out.println("网虫套餐:上网流量:5GB,月资费:68元");
			if (w == true) {
				result(price2);
			}
			break;
		case 3:// 超人套餐
				// String cr="超人套餐:通话时长:200分钟, 短信条数:100条,上网流量:1GB,月资费:78元";
			xh = 3;
			boolean flag2 = Tlist.isEmpty();
			boolean fl2 = blist.isEmpty();
			if (flag2 == false || fl2 == false) {
				Tlist.removeAll(Tlist);
				blist.removeAll(blist);
				changmeal();
			}
			int price3 = 78;
			SuperPackage cr = new SuperPackage();
			cr.setChat(1000);
			cr.setMinutes(200);
			cr.setTexts(100);
			cr.setPrice(price3);
			clist.add(cr);
			System.out.println("超人套餐:通话时长:200分钟, 短信条数:100条,上网流量:1GB,月资费:78元");
			if (w == true) {
				result(price3);
			}
			break;
		}
	}

	public void result(int price) {
		Scanner sca = new Scanner(System.in);
		System.out.println("请输入姓名");
		String name = sca.next();
		System.out.println("请输入密码");
		String pwd = sca.next();
		System.out.println("请输入预存话费金额:");
		int ycmoney = sca.nextInt();
		sumMoney = ycmoney;
		int money = ycmoney - price;
		System.out.print("注册成功!");
		System.out.print("卡号:" + list[kh - 1] + "用户名:" + name + "当前余额:" + money
				+ "元\n");
		long dh = list[kh - 1];
		Account a1 = new Account();
		a1.setCardNo(dh);
		a1.setName(name);
		a1.setPwd(pwd);
		a1.setTaocan(price);
		a1.setMoney(money);
		alist.add(a1);
	}

	public void login() throws Exception { // 登录
		Scanner sca = new Scanner(System.in);
		System.out.println("请输入手机卡号:");
		long cardNo = sca.nextLong();
		System.out.println("请输入密码:");
		String strpwd = sca.next();
		boolean flag = false;
		for (int i = 0; i < alist.size(); i++) {
			if (alist.get(i).getCardNo() == cardNo
					&& alist.get(i).getPwd().equals(strpwd)) {
				flag = true;
				break;
			}
		}
		if (flag == true) {
			meal();
		}
		if (flag == false) {
			System.out.println("输入手机卡号或密码不正确,请重新输入");
			login();
		}
	}

	public void meal() throws Exception { // 嗖嗖移动用户菜单
		System.out.println("*****嗖嗖移动用户菜单*****");
		System.out.println("1.本月账单查询2.套餐余量查询3.打印消费详单  4.套餐变更5.办理退网");
		System.out.println("请选择(输入1~5选择功能,其他键返回上一级):");
		Scanner sca = new Scanner(System.in);
		int num = sca.nextInt();
		switch (num) {
		case 1:// 本月账单查询
			for (int i = 0; i < alist.size(); i++) {
				System.out.println("您的卡号:" + alist.get(i).getCardNo()
						+ ",当月账单:");
				System.out.println("套餐资费:" + alist.get(i).getTaocan() + "元");
				System.out.println("合计消费:"
						+ (sumMoney - alist.get(i).getMoney()) + "元");
				System.out.println("账户余额:" + alist.get(i).getMoney() + "元");
				break;
			}
			meal();
			break;
		case 2:// 套餐余量查询
			System.out.println("*****套餐余量查询******");
			for (int i = 0; i < alist.size(); i++) {
				System.out.println("您的卡号是" + alist.get(i).getCardNo());
				break;
			}
			if (xh == 1) {
				for (int i = 0; i < Tlist.size(); i++) {
					if (Tlist.get(i).getMinutes() < 0) {
						Tlist.get(i).setMinutes(0);
					}
					if (Tlist.get(i).getTexts() < 0) {
						Tlist.get(i).setTexts(0);
					}
					System.out.println("套餐内剩余:\n免费通话时长剩余:"
							+ Tlist.get(i).getMinutes() + "分钟\n免费短信条数剩余:"
							+ Tlist.get(i).getTexts() + "条");
					break;
				}
			}
			if (xh == 2) {
				for (int i = 0; i < blist.size(); i++) {
					System.out.println("套餐内剩余:\n套餐流量剩余:"
							+ blist.get(i).getChat() + "M");
					break;
				}
			}
			if (xh == 3) {
				for (int i = 0; i < Tlist.size(); i++) {
					if (clist.get(i).getMinutes() < 0) {
						clist.get(i).setMinutes(0);
					}
					if (clist.get(i).getTexts() < 0) {
						clist.get(i).setTexts(0);
					}
					if (clist.get(i).getChat() < 0) {
						clist.get(i).setChat(0);
					}
					System.out.println("套餐内剩余:\n免费通话时长剩余:"
							+ clist.get(i).getMinutes() + "分钟\n免费短信条数剩余:"
							+ clist.get(i).getTexts() + "条\n套餐流量剩余:"
							+ clist.get(i).getChat() + "M");
					break;
				}
			}
			meal();
			break;
		case 3:// 打印消费详单
			System.out.println("消费记录如下:");
			for (int i = 0; i < dylist.size(); i++) {
				System.out.println(dylist.get(i).getList());
			}
			System.out.println("消费记录打印完毕!");
			meal();
			break;
		case 4:// 套餐变更
			taocan();
			meal();
			break;
		case 5:// 办理退网
			alist.removeAll(alist);
			if (alist.isEmpty() == true) {
				Tlist.removeAll(Tlist);
				blist.removeAll(blist);
				clist.removeAll(clist);
				System.out.println("*****办理退网******\n卡号" + kh + "办理退网成功!");
			}
			break;
		default:
			init();
			break;
		}
	}

	public void soso() throws Exception {
		Scanner sca = new Scanner(System.in);
		System.out.println("输入卡号");
		long tel = sca.nextLong();
		Random r = new Random();
		int a = r.nextInt(2);// 0-1
		Account ac = new Account();
		List list = new ArrayList();
		int c = r.nextInt(3);// 0-2
		for (int j = 0; j < alist.size(); j++) {
			if (alist.get(j).getMoney() < 0) {
				System.out.println("已欠费,服务无法连接,请充话费");
				break;
			} else {
				if (xh == 1) {
					TalkPackage talk = new TalkPackage();// 话痨套餐
					for (int i = 0; i < Tlist.size(); i++) {
						if (a == 0) {
							talk.setMinutes(Tlist.get(i).getMinutes());
							talk.call();
							String str1 = "给小华打了50分钟电话";
							list.add(str1);
							ac.setList(list);
							dylist.add(ac);
							Tlist.get(i).setMinutes(talk.getMinutes());
							if ((Tlist.get(i).getMinutes() < 0)) {
								System.out.println("免费通话已用完,超出套餐计费:0.2元/分钟");
								double kc = (Tlist.get(i).getMinutes() * (-1) * 0.2);
								for (int k = 0; k < alist.size(); k++) {
									double out = (alist.get(k).getMoney()) - kc;
									alist.get(k).setMoney(out);
									System.out.println("扣费金额为:" + kc + "元");
									break;
								}
							}
							break;
						}
						if (a == 1) {
							talk.setTexts(Tlist.get(j).getTexts());
							talk.text();
							String str2 = "向小明发了25条短信";
							list.add(str2);
							ac.setList(list);
							Tlist.get(i).setTexts(talk.getTexts());
							if ((Tlist.get(i).getTexts() < 0)) {
								System.out.println("免费短信已用完,超出套餐计费:0.1元/条");
								double kc = (talk.getTexts() * (-1) * 0.1);// 扣费金额
								for (int k = 0; k < alist.size(); k++) {
									double out = (alist.get(k).getMoney()) - kc;
									alist.get(k).setMoney(out);
									System.out.println("总扣费金额为:" + kc + "元");
									break;
								}
								break;
							}
						}
					}
				}
				if (xh == 2) {
					NetPackage np = new NetPackage();
					for (int j2 = 0; j2 < blist.size(); j2++) {
						np.setChat(blist.get(j2).getChat());
						np.net();
						String str2 = "和 过客 开视频 使用500M流量";
						list.add(str2);
						ac.setList(list);
						dylist.add(ac);
						blist.get(j2).setChat(np.getChat());
						if ((blist.get(j2).getChat() < 0)) {
							System.out.println("免费流量已用完,超出套餐计费:0.1元/M");
							double kc = (blist.get(j2).getChat() * (-1) * 0.1);
							for (int k = 0; k < alist.size(); k++) {
								double out = (alist.get(k).getMoney()) - kc;
								alist.get(k).setMoney(out);
								System.out.println("扣费金额为:" + kc + "元");
								break;
							}
						}
						break;
					}

				}
				if (xh == 3) {
					SuperPackage sp = new SuperPackage();
					for (int j3 = 0; j3 < clist.size(); j3++) {
						if (c == 0) {
							sp.setMinutes(clist.get(j3).getMinutes());
							sp.call();
							String str1 = "给   aaa 打了25分钟电话";
							list.add(str1);
							ac.setList(list);
							dylist.add(ac);
							clist.get(j3).setMinutes(sp.getMinutes());
							if ((clist.get(j3).getMinutes() < 0)) {
								System.out.println("免费通话已用完,超出套餐计费:0.2元/分钟");
								double kc = (clist.get(j3).getMinutes() * (-1) * 0.2);
								for (int k = 0; k < alist.size(); k++) {
									double out = (alist.get(k).getMoney()) - kc;
									alist.get(k).setMoney(out);
									System.out.println("扣费金额为:" + kc + "元");
									break;
								}
							}
							break;
						}
						if (c == 1) {
							sp.setTexts(clist.get(j3).getTexts());
							sp.text();
							String str2 = "向 aa 发了10条短信";
							list.add(str2);
							ac.setList(list);
							clist.get(j3).setTexts(sp.getTexts());
							if ((clist.get(j3).getTexts() < 0)) {
								System.out.println("免费短信已用完,超出套餐计费:0.1元/条");
								double kc = (sp.getTexts() * (-1) * 0.1);// 扣费金额
								for (int k = 0; k < alist.size(); k++) {
									double out = (alist.get(k).getMoney()) - kc;
									alist.get(k).setMoney(out);
									System.out.println("总扣费金额为:" + kc + "元");
									break;
								}
								break;
							}
						}
						if (c == 2) {
							sp.setChat(clist.get(j3).getChat());
							sp.net();
							String str2 = "和 aaa 开视频 使用500M流量";
							list.add(str2);
							ac.setList(list);
							dylist.add(ac);
							clist.get(j3).setChat(sp.getChat());
							if ((clist.get(j3).getChat() < 0)) {
								System.out.println("免费流量已用完,超出套餐计费:0.1元/M");
								double kc = (clist.get(j3).getChat() * (-1) * 0.1);
								for (int k = 0; k < alist.size(); k++) {
									double out = (alist.get(k).getMoney()) - kc;
									alist.get(k).setMoney(out);
									System.out.println("扣费金额为:" + kc + "元");
									break;
								}
							}
							break;
						}
					}
				}

				break;
			}
		}
	}

	public void changmeal() throws Exception {// 变更扣费
		Account a = new Account();
		if (xh == 1) {
			for (int i = 0; i < alist.size(); i++) {
				alist.get(i).setMoney(alist.get(i).getMoney() - 58);
				if (alist.get(i).getMoney() < 0) {
					System.out.println("话费不足,变更失败");
					meal();
					break;
				} else {
					System.out.println("变更成功");
					break;
				}
			}
		}
		if (xh == 2) {
			for (int i = 0; i < alist.size(); i++) {
				alist.get(i).setMoney(alist.get(i).getMoney() - 68);
				if (alist.get(i).getMoney() < 0) {
					System.out.println("变更失败");
					meal();
					break;
				} else {
					System.out.println("变更成功");
					break;
				}
			}
		}
		if (xh == 3) {
			for (int i = 0; i < alist.size(); i++) {
				alist.get(i).setMoney(alist.get(i).getMoney() - 78);
				if (alist.get(i).getMoney() < 0) {
					System.out.println("变更失败");
					meal();
					break;
				} else {
					System.out.println("变更成功");
					break;
				}
			}
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值