/*
* @author:杨晓东
* @date:2014-04-06
* 我行我素购物系统
*/
import java.util.Scanner;// 导入一个外部的java类
public class MyShop {
public static void main(String [] args){
/*
需求:用户输入登录,如果登录失败,继续重新登录,失败次数超过三次,退出系统
*/
int loginIndex = 0;// 定义一个变量,存放用户登录失败的次数
//第一个板块
picture1:
while(true) {
// 展示登录菜单
System.out.println("\t\t欢迎光临我行我素购物管理系统1.0版");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.println("\t\t\t1. 登 录 系 统");
System.out.println(" ");
System.out.println("\t\t\t2.更 改 用 户 密 码");
System.out.println(" ");
System.out.println("\t\t\t3. 退 出");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
// 提示用户输入选项
System.out.print("请输入您的选项:");
Scanner input = new Scanner(System.in);
int choice1 = input.nextInt();
// 判断用户输入选项是否正确
if(choice1 == 1) {/*登录系统*/
// 登录系统要实现的功能:提示用户输入用户名和密码
System.out.print("请输入用户名:");
String username = input.next();
System.out.print("请输入密码:");
String password = input.next();
// 判断用户输入的用户名是否admin,密码是否1111
/* 整数判断可以用==;字符串是否相等判断,用equals方法*/
if("yangxiaodong".equals(username) && "qwer".equals(password)){
// 登录成功之后,系统后续要做的工作
System.out.println("登录成功...");
} else {
//输入次数的判断
loginIndex ++;
if(loginIndex > 2) {
System.out.println("您的输入已经超过上限,请重新登录");
System.exit(1);//系统退出
}
System.out.println("您的用户名或者密码有误,请重新登录");
continue;
}
break;
//上面第一个if的括号 if(choice1 == 1)
}else if(choice1 == 2) {/*更改管理员密码,提示系统升级...*/
System.out.println("系统正在升级中...");
System.out.println("请重新登录");
continue;
}else if (choice1 ==3){/*退出系统*/
System.out.println("系统即将推出...");
System.exit(1);//系统推出
}else {/*没有这个选项*/
System.out.println("对不起,没有该选项");
System.out.print("请重新输入您的选择:");
choice1 = input.nextInt();
continue;
}
break;
}//第一个while的括号
//第二个板块
picture2:
while (true){
//第二个循环
System.out.println("\t\t\t欢迎使用我行我素购物管理系统");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.println("\t\t\t1. 客 户 信 息 管 理");
System.out.println(" ");
System.out.println("\t\t\t2. 购 物 结 算");
System.out.println(" ");
System.out.println("\t\t\t3. 真 情 回 馈");
System.out.println(" ");
System.out.println("\t\t\t4. 返 回 上 一 级");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.print("请输入您的选择:");
Scanner input = new Scanner(System.in);
int choice2 = input.nextInt();
//用while循环来说明没有的选项
while (choice2 != 1 && choice2 != 2 && choice2 != 3 && choice2 != 4)
{
System.out.println("没有这个选项,请重新输入");
/*System.out.print("请重新输入您的选择:");
choice2 = input.nextInt();//这里重新定义一个新的变量就会重复出现一次上一个界面*/
//退出此循环
if(choice2 == 1 || choice2 == 2 || choice2 == 3 || choice2 == 4){
break;
}
}
//在外部定义所有客户信息
String username1 ="小猫";
String username2 ="小狗";
String username3 ="小马";
String username4 ="小狐狸";
String username5 ="大象";
String birthday1 ="1992-7-10";
String birthday2 ="1992-6-17";
String birthday3 ="1992-7-10";
String birthday4 ="1992-11-1";
String birthday5 ="1992-11-17";
//第二个界面的选择
if (choice2 == 1){
//choice2 == 1时显示
System.out.println("我行我素购物管理系统>客户信息管理");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.println("\t\t\t1. 显 示 所 有 客 户 信 息");//可以有
System.out.println(" ");
System.out.println("\t\t\t2. 添 加 客 户 信 息");//不会
System.out.println(" ");
System.out.println("\t\t\t3. 修 改 客 户 信 息");//不会
System.out.println(" ");
System.out.println("\t\t\t4. 查 询 客 户 信 息");//可以有
System.out.println(" ");
System.out.println("\t\t\t5. 返 回 上 一 级");//可以有
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.print("请输入您的选择:");
int choice3 = input.nextInt();
//用一个while循环来说明没有的选项
while (choice3 != 1 && choice3 != 2 && choice3 != 3 && choice3 != 4 && choice3 != 5)
{
System.out.println("没有这个选项,请重新输入");
//退出此循环
if(choice3 == 1 || choice3 == 2 || choice3 == 3 || choice3 == 4 || choice3 == 5){
break;
}
}//对应 while 的大括号
if (choice3 == 1) {
//显示所有客户信息
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1001\t\t"+username1+"\t\t"+birthday1+"\t\t20000");
System.out.println("1001\t\t"+username2+"\t\t"+birthday2+"\t\t25000");
System.out.println("1001\t\t"+username3+"\t\t"+birthday3+"\t\t30000");
System.out.println("1001\t\t"+username4+"\t\t"+birthday4+"\t\t10000");
System.out.println("1001\t\t"+username5+"\t\t"+birthday5+"\t\t10000");
System.out.print("请按任意键继续!");
String a = input.next();
continue;
}
if(choice3 == 2){
System.out.println("系统正在升级中...");
System.out.print("按任意数字返回继续");
String b = input.next();
continue;
}
if (choice3 == 3){
System.out.println("系统正在升级中...");
System.out.print("按任意数字返回继续");
String c = input.next();
continue;
}
if(choice3 ==4){
System.out.print("请输入您要查询的客户编号:");
int number = input.nextInt();
//同样是做一个do-while说明没有其他的选项
while (number != 1001 && number != 1002 && number != 1003 && number != 1004 && number != 1005)
{
System.out.print("对不起,没有该选项");
System.out.print("请重新输入您的选择:");
choice3 = input.nextInt();
if (number == 1001 || number == 1002 || number == 1003 || number == 1004 || number == 1005){
break;
}
}
switch (number){
case 1001:
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1001\t\t"+username1+"\t\t"+birthday1+"\t\t20000");
System.out.print("按任意键返回继续");
String d = input.next();
continue;
case 1002:
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1002\t\t"+username2+"\t\t"+birthday2+"\t\t20000");
System.out.print("按任意键返回继续");
String e = input.next();
continue;
case 1003:
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1003\t\t"+username3+"\t\t"+birthday3+"\t\t20000");
System.out.print("按任意键返回继续");
String f = input.next();
continue;
case 1004:
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1004\t\t"+username1+"\t\t"+birthday1+"\t\t20000");
System.out.print("按任意键返回继续");
String g = input.next();
continue;
case 1005:
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1005\t\t"+username5+"\t\t"+birthday5+"\t\t20000");
System.out.print("按任意键返回继续");
String h = input.next();
continue;
}//对应switch的大括号
}//对应choice3 = 4的大括号
if (choice3 == 5){
continue picture2;
}
}//if (choice2 == 1)所对应的大括号
//对应选择2购物结算
if (choice2 == 2){
System.out.print("欢迎进入购物系统!");
System.out.print("请输入您的客户编号");
}
//定义上面输入的编号
int number1 = input.nextInt();
//第3个板块
picture3:
while (number1 == 1001 || number1 == 1002 || number1 == 1003 || number1 == 1004 || number1 == 1005 )
{
System.out.println("商城现有商品如下:");
System.out.println("商品编号\t\t商品名称\t\t商品价格");
System.out.println("1\t\t云南白药\t\t¥18.00");
System.out.println("2\t\t小米手机\t\t¥1999.00");
System.out.println("3\t\t小黑\t\t¥4998.00");
System.out.println("4\t\t拖鞋\t\t¥25.80");
System.out.println("5\t\t酱油\t\t¥5.60");
System.out.println("6\t\t汽车模型\t\t¥350.00");
System.out.println("7\t\t坦克模型\t\t¥400.00");
System.out.println("8\t\t玩具枪\t\t¥99.80");
System.out.println("请输入您要购买的产品编号");
int number2 = input.nextInt();
System.out.println("请输入您要购买的产品数量");
int amount = input.nextInt();
if (number1 != 1001 && number1 != 1002 && number1 != 1003 && number1 != 1004 && number1 != 1005)
{
System.out.print("对不起,没有该选项");
number2 = input.nextInt();
continue;
}
String name = null;
double price = 0; //定义2个变量
switch (number2){
case 1:
name = "云南白药";
price = 18.00;
break;
case 2:
name = "小米手机";
price = 1998.00;
break;
case 3:
name = "小黑";
price = 4998.00;
break;
case 4:
name = "拖鞋";
price = 25.00;
break;
case 5:
name = "酱油";
price = 5.60;
break;
case 6:
name = "汽车模型";
price = 350.00;
break;
case 7:
name = "坦克模型";
price = 400.00;
break;
case 8:
name = "玩具枪";
price = 99.80;
break;
default:
System.out.println("没有您需要的商品编号...");
break;
}
//用户的判断
if(number2 == 1001){
System.out.println("尊敬的用户:小猫");
}
else if(number2 == 1002){
System.out.println("尊敬的用户:小狗");
}
else if(number2 == 1003){
System.out.println("尊敬的用户:小马");
}
else if(number2 == 1004){
System.out.println("尊敬的用户:小狐狸");
}
else if(number2 == 1005){
System.out.println("尊敬的用户:大象");
}
else{
System.out.println("没有该用户...");
}
int value = (int)(price * amount * 0.85);//强制类型转换,可能会失精度
double money = price * amount;
System.out.println("尊敬的用户:小猫");
System.out.println("产品名称\t\t产品单价\t\t购买数量\t\t产品总价");
System.out.println(name + "\t\t" + price + "\t\t" + amount + "\t\t"+ money);
System.out.println("您购买产品总价为:" + money);
System.out.println("按您当前的积分,您的折扣是:0.85");
System.out.println("您的应付款为:" + value);
System.out.println("请付款:");
double total = input.nextDouble();
double change = total - value;
if (total > value){
System.out.println("付款成功!");
System.out.println("找零:" + change);
System.out.println("欢迎下次光临!");
continue picture2;
}else{
System.out.println("请重新宠幸本系统...");
}
}
if(choice2 == 3){
System.out.println("我行我素购物管理系统>真情回馈");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.println("1. 幸 运 大 放 送");
System.out.println(" ");
System.out.println("2. 幸 运 抽 奖");
System.out.println(" ");
System.out.println("3. 真 情 问 候");
System.out.println(" ");
System.out.println("4. 返 回 上 一 级");
System.out.println(" ");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(" ");
System.out.print("请输入您的选择:");
int choice4 = input.nextInt();
if(choice4 == 1){
System.out.println("积分最高的客户是:");
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1003\t\t小马\t\t1992-7-10\t\t30000");
System.out.println("恭喜以上用户,获得价值¥5888.00的 iphoe 5S!!");
System.out.println("请按任意键继续");
String suiyi9 = input.next();
continue picture2;
}
else if(choice4 ==2){
System.out.println("积分最高的客户是:");
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out.println("1001\t\t小猫\t\t1992-7-10\t\t20000");
System.out.println("恭喜以上用户,获得价值¥50元的话费充值卡!!");
System.out.println("请按任意键继续");
String suiyi10 = input.next();
continue picture2;
}
else if(choice4 == 3){
System.out.println("今天没有过生日的客户");
System.out.println("请按任意键继续");
String suiyi11 = input.next();
continue picture2;
}
else{
System.out.println("对不起,没有该选项");
continue picture2;
}
}//对应picture2
}
}
}