一个能实现大部分购买商品功能的程序

/**
 * 一个能实现大部分购买商品功能的程序
 * author:卢璞
 * date:2014.4.17
 */
public class Project{
	public static void main(String [] args){
		zuiwaiceng:
		while (true){
		System.out.println("\t\t\t欢迎使用我行我素购物管理系统1.0版\n");
		System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.println("\t\t\t\t1. 登 录 系 统\n");
		System.out.println("\t\t\t\t2.更  改 管 理 员 密 码\n");
		System.out.println("\t\t\t\t3.  退  出\n");
		System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
        System.out.print("请输入您的选择:");


		java.util.Scanner input=new java.util.Scanner(System.in);
		int choice=input.nextInt();
		int question = 0;
		int n = 3;


		while (choice != 1 && choice != 2 && choice != 3){
			System.out.print("没有此选项,请重新输入:");
			choice=input.nextInt();
			if (choice == 1 || choice == 2 || choice == 3){
				break;
			}
		}


		while (choice == 2){
			System.out.print("此功能正在升级中,请重新输入:");
			choice=input.nextInt();
			if (choice != 2){
				break;
			}
		}

		while (true){
		if (choice == 3){
			System.out.println("系统即将退出...");
			System.exit(1);
		}else if (choice == 1){
			System.out.println("请输入用户名:");
			String username=input.next();
			System.out.println("请输入密码:");
			String password=input.next();
			if ("admin".equals(username) && "heihei".equals(password)){
				dierceng:
				while (true){
				String a = "护花使者张泽宇";
				String b = "教主李洪志";
				String c = "傻x祁航";
				String d = "逗x吴越";
				String e = "逗x";

				String a1 = "1992-7-10";
				String b1 = "1992-6-17";
				String c1 = "1992-7-10";
				String d1 = "1992-11-1";
				String e1 = "1992-11-17";

				System.out.println("\t\t\t欢迎使用我行我素购物管理系统\n");
				System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
				System.out.println("\t\t\t\t1. 客 户 信 息 管 理\n");
				System.out.println("\t\t\t\t2. 购 物 结 算\n");
				System.out.println("\t\t\t\t3. 真 情 回 馈\n");
				System.out.println("\t\t\t\t4. 返 回 上 一 级\n");
				System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
				System.out.print("请输入您的选择:");
				int choice2=input.nextInt();
				while (choice2 != 1&& choice2 != 2 && choice2 != 3 && choice2 != 4){
					System.out.println("没有此选项,请重新输入:");
					choice2=input.nextInt();
					if (choice2 == 1 || choice2 == 2 || choice2 == 3 || choice2 == 4)
					{break;
					}
				}
				
				if (choice2 == 1){
					while (true){
					System.out.println("\t\t1.显 示 所 有 客 户 信 息\n");
					System.out.println("\t\t2.添 加 客 户 信 息\n");
					System.out.println("\t\t3.修 改 客 户 信 息\n");
					System.out.println("\t\t4.查 询 客 户 信 息\n");
					System.out.println("\t\t5.返 回 上 一 级\n");
					System.out.print("请输入您的选择:");
					int x=input.nextInt();
					while (x != 1 && x != 2 && x != 3 && x != 4 && x != 5){
						System.out.println("输入有误,请重新输入:");
						x=input.nextInt();
						if (x == 1 || x == 2 || x == 3 || x == 4 || x == 5){
							break;
						}
					}
					while (x == 2){
						System.out.println("对不起,该功能正在升级中,请选择其他选项:");
						x=input.nextInt();
						if (x != 2){
							break;
						}
					}
					if (x == 1){
						System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
						System.out.println("1001\t\t\t"+ a +"\t\t"+ a1 +"\t\t"+"20000\n");
						System.out.println("1002\t\t\t"+ b +"\t\t"+ b1 +"\t\t"+"25000\n");
						System.out.println("1003\t\t\t"+ c +"\t\t"+ c1 +"\t\t"+"30000\n");
						System.out.println("1004\t\t\t"+ d +"\t\t"+ d1 +"\t\t"+"10000\n");
						System.out.println("1005\t\t\t"+ e +"\t\t"+ e1 +"\t\t"+"10000\n");
						System.out.println("请按任意键退出...");
						String num=input.next();
						continue;
					}else if (x == 3){
						System.out.println("请输入您想要修改的客户编号:");
						int amend =input.nextInt();
						while (amend != 1001 && amend != 1002 && amend != 1003 && amend != 1004 && amend !=1005){
							System.out.println("对不起,您输入的客户信息不存在!\n");
							System.out.print("请重新输入:");
							amend =input.nextInt();
							if (amend == 1001 || amend == 1002 || amend == 1003 || amend == 1004 || amend == 1005){
								break;
							}
						}
						if (amend == 1001){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1001\t\t\t"+ a +"\t\t"+ a1 +"\t\t"+"20000\n");
							System.out.println("请选择您要修改的内容:1.姓名    2.生日");
							System.out.print("请输入您的选择:");
							int amendchoice=input.nextInt();
							while (amendchoice != 1 && amendchoice != 2){
								System.out.print("输入有误,请重新输入:");
								amendchoice=input.nextInt();
								if (amendchoice == 1 || amendchoice == 2){
									break;
								}
							}
							if (amendchoice == 1){
								System.out.println("请输入新的客户名称:");
								a =input.next();
								System.out.println("修改成功!");
								System.out.println("请按任意键退出...");
						        String num=input.next();
						        continue;
							}else if (amendchoice == 2){
                                 System.out.println("请输入新的客户生日:(格式yyyy-MM-dd)");
								 a1 =input.next();
								 System.out.println("修改成功!");
								 System.out.println("请按任意键退出...");
						         String num=input.next();
						         continue;
							}
						}else if (amend == 1002){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1002\t\t\t"+ b +"\t\t"+ b1 +"\t\t"+"25000\n");
							System.out.println("请选择您要修改的内容:1.姓名    2.生日");
							System.out.print("请输入您的选择:");
							int amendchoice=input.nextInt();
							while (amendchoice != 1 && amendchoice != 2){
								System.out.print("输入有误,请重新输入:");
								amendchoice=input.nextInt();
								if (amendchoice == 1 || amendchoice == 2){
									break;
								}
							}
							if (amendchoice == 1){
								System.out.println("请输入新的客户名称:");
								b =input.next();
								System.out.println("修改成功!");
								System.out.println("请按任意键退出...");
						        String num=input.next();
						        continue;
							}else if (amendchoice == 2){
                                 System.out.println("请输入新的客户生日:(格式yyyy-MM-dd)");
								 b1 =input.next();
								 System.out.println("修改成功!");
								 System.out.println("请按任意键退出...");
						         String num=input.next();
						         continue;
							}
						}else if (amend == 1003){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1003\t\t\t"+ c +"\t\t"+ c1 +"\t\t"+"30000\n");
							System.out.println("请选择您要修改的内容:1.姓名    2.生日");
							System.out.print("请输入您的选择:");
							int amendchoice=input.nextInt();
							while (amendchoice != 1 && amendchoice != 2){
								System.out.print("输入有误,请重新输入:");
								amendchoice=input.nextInt();
								if (amendchoice == 1 || amendchoice == 2){
									break;
								}
							}
							if (amendchoice == 1){
								System.out.println("请输入新的客户名称:");
								c =input.next();
								System.out.println("修改成功!");
								System.out.println("请按任意键退出...");
						        String num=input.next();
						        continue;
								
							}else if (amendchoice == 2){
                                 System.out.println("请输入新的客户生日:(格式yyyy-MM-dd)");
								 c1 =input.next();
								 System.out.println("修改成功!");
								 System.out.println("请按任意键退出...");
						         String num=input.next();
						         continue;
							}
						}else if (amend == 1004){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1004\t\t\t"+ d +"\t\t"+ d1 +"\t\t"+"10000\n");
							System.out.println("请选择您要修改的内容:1.姓名    2.生日");
							System.out.print("请输入您的选择:");
							int amendchoice=input.nextInt();
							while (amendchoice != 1 && amendchoice != 2){
								System.out.print("输入有误,请重新输入:");
								amendchoice=input.nextInt();
								if (amendchoice == 1 || amendchoice == 2){
									break;
								}
							}
							if (amendchoice == 1){
								System.out.println("请输入新的客户名称:");
								d =input.next();
								System.out.println("修改成功!");
								System.out.println("请按任意键退出...");
						        String num=input.next();
						        continue;
							}else if (amendchoice == 2){
                                 System.out.println("请输入新的客户生日:(格式yyyy-MM-dd)");
								 d1 =input.next();
								 System.out.println("修改成功!");
								 System.out.println("请按任意键退出...");
						         String num=input.next();
						         continue;
							}
						}else if (amend == 1005){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1005\t\t\t"+ e +"\t\t"+ e1 +"\t\t"+"10000\n");
							System.out.println("请选择您要修改的内容:1.姓名    2.生日");
							System.out.print("请输入您的选择:");
							int amendchoice=input.nextInt();
							while (amendchoice != 1 && amendchoice != 2){
								System.out.print("输入有误,请重新输入:");
								amendchoice=input.nextInt();
								if (amendchoice == 1 || amendchoice == 2){
									break;
								}
							}
							if (amendchoice == 1){
								System.out.println("请输入新的客户名称:");
								e =input.next();
								System.out.println("修改成功!");
								System.out.println("请按任意键退出...");
						        String num=input.next();
						        continue;
							}else if (amendchoice == 2){
                                 System.out.println("请输入新的客户生日:(格式yyyy-MM-dd)");
								 e1 =input.next();
								 System.out.println("修改成功!");
								 System.out.println("请按任意键退出...");
						         String num=input.next();
						         continue;
							}
						}
					}else if (x == 4){
						System.out.println("请输入您想要查询的客户编号:");
						int amend =input.nextInt();
						while (amend != 1001 && amend != 1002 && amend != 1003 && amend != 1004 && amend !=1005){
							System.out.println("对不起,您想要查询的客户不存在!\n");
							System.out.print("请重新输入:");
							amend =input.nextInt();
							if (amend == 1001 || amend == 1002 || amend == 1003 || amend == 1004 || amend == 1005){
								break;
							}
						}
						if (amend == 1001){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1001\t\t\t"+ a +"\t\t"+ a1 +"\t\t"+20000);
							System.out.println("请按任意键退出...");
						    String num=input.next();
						    continue;
						}else if (amend == 1002){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1002\t\t\t"+ b +"\t\t"+ b1 +"\t\t"+25000);
							System.out.println("请按任意键退出...");
						    String num=input.next();
						    continue;
						}else if (amend == 1003){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1003\t\t\t"+ c +"\t\t"+ c1 +"\t\t"+30000);
							System.out.println("请按任意键退出...");
						    String num=input.next();
						    continue;
						}else if (amend == 1004){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1004\t\t\t"+ d +"\t\t"+ d1 +"\t\t"+10000);
							System.out.println("请按任意键退出...");
						    String num=input.next();
						    continue;
						}else if (amend == 1005){
							System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
							System.out.println("1005\t\t\t"+ e +"\t\t"+ e1 +"\t\t"+10000);
							System.out.println("请按任意键退出...");
						    String num=input.next();
						    continue;
						}
					}else if (x == 5){
						continue dierceng;
					}
					}// 客户信息那里的while
				}else if (choice2 == 2){
					System.out.println("欢迎进入购物系统!\n");
					System.out.print("请输入您的客户编号:");
					int amend =input.nextInt();
					while (amend != 1001 && amend != 1002 && amend != 1003 && amend != 1004 && amend !=1005){
						System.out.println("对不起,您输入的客户信息不存在!\n");
						System.out.print("请重新输入:");
						amend =input.nextInt();
						if (amend == 1001 || amend == 1002 || amend == 1003 || amend == 1004 || amend == 1005){
								break;
						}
					}
					System.out.println("商城现有商品如下:\n");
					System.out.println("商品编号\t\t商品名称\t\t商品价格\t\t\n");
					System.out.println("1\t\t\t云南白药\t\t¥18.00\n");
					System.out.println("2\t\t\t小米手机\t\t¥1998.00\n");
					System.out.println("3\t\t\t小黑\t\t¥4998.00\n");
					System.out.println("4\t\t\t拖鞋\t\t¥25.00\n");
					System.out.println("5\t\t\t酱油\t\t¥5.60\n");
					System.out.println("6\t\t\t汽车模型\t\t¥350.00\n");
					System.out.println("7\t\t\t坦克模型\t\t¥400.00\n");
					System.out.println("8\t\t\t玩具枪\t\t¥99.80\n");
					System.out.println("请输入您要购买的商品编号:");
					int num3=input.nextInt();
					// 若用户输入不为1,且不为2、3、4、5、6、7、8,则进入如下循环程序
					while (num3 != 1 &&num3 != 2 &&num3 != 3 &&num3 != 4 &&num3 !=5 &&num3 != 6 &&num3 != 7 &&num3 != 8)
					{
					System.out.print("对不起,没有您要购买的商品,请重新输入:");
					// 用户再次输入选择,直到为1或2、3、4、5、6、7、8可跳出此循环
					num3 = input.nextInt();
					if (num3 ==1 && num3 ==2 && num3 ==3 && num3 ==4 && num3 ==5 && num3 ==6 && num3 ==7 && num3 ==8)
			        {break;
			        }
					}
					System.out.println("请输入您要购买的产品数量:");
					// 定义一个整型变量,接收用户从键盘输入的数据,即为用户要购买的产品数量
					int num4=input.nextInt();
					// 定义一个字符串变量,并先给其一初始值,即为用户购买商品名称
					String name=null;
					// 定义一个浮点型变量,并先给其一初始值,即为购买商品单价
					double price = 0.00;
					// 根据用户输入要购买的商品序号,对String和price进行匹配
					switch (num3)
					{
					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.0;
						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;
					}
					// 定义一个浮点型变量,作为用户本应付款数
					double sum = num4 * price;
					// 定义一个浮点型变量,根据打折程度,作为用户实际需要付款数
					double pay = sum * 0.85;
					String mingzi = null;
					if (amend == 1001){mingzi = "小猫";
					}else if (amend == 1002){mingzi = "小狗";
					}else if (amend == 1003){mingzi = "小马";
					}else if (amend == 1004){mingzi = "小狐狸";
					}else if (amend == 1005){mingzi = "大象";
					}
					System.out.println("尊敬的用户:"+ mingzi + "\n");
					System.out.println("产品名称\t产品单价\t购买数量\t产品总价\n");
					System.out.println(name+"\t¥"+price+"\t"+num4+"\t\t¥"+sum);
					System.out.println("您购买的商品总价为:"+sum);
					System.out.println("按您当前积分,您的折扣为:0.85");
					System.out.println("您的应付款为:"+pay);
					System.out.print("请付款:");
					// 定义变量z,接收用户从键盘输入的实际付款
					double z=input.nextDouble();
					// 当用户实际付款不足,进行提示并进行如下循环程序
					while (z < pay){
						System.out.print("对不起,您的付款不足,请重新付款:");
						//用户再次输入付款数,当满足条件时可跳出此循环
						z=input.nextDouble();
						if ( z > pay)
						{break;
						}
					}if (z >= pay){
						double x =z - pay;
						System.out.println("付款成功!");
						System.out.println("找零:¥" + x);
						System.out.print("欢迎下次光临!\n");
						System.out.println("请按任意键退出...");
						String num=input.next();
						continue;
						
						
					}	
				}else if (choice2 == 3){
					while (true){
					System.out.println("\t\t\t欢迎进入我行我素购物管理系统真情回馈界面\n");
					System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
					System.out.println("\t\t\t1.幸 运 大 放 送\n");
					System.out.println("\t\t\t2.幸 运 抽 奖\n");
					System.out.println("\t\t\t3.生 日 问 候\n");
					System.out.println("\t\t\t4.返 回 上 一 级\n");
					System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
					System.out.println("请输入您的选择:");
					int xuanze=input.nextInt();
					while (xuanze != 1&& xuanze != 2 && xuanze != 3 && xuanze != 4){
					    System.out.println("没有此选项,请重新输入:");
					    xuanze=input.nextInt();
					    if (xuanze == 1 || xuanze == 2 || xuanze == 3 || xuanze == 4)
					    {break;
					    }
				    }
					if (xuanze == 1){
						System.out.println("积分最高的客户是:\n");
						System.out.println("客户编号\t\t客户姓名\t\t客户生日\t客户积分");
						System.out.println("1003\t\t\t"+ c +"\t\t\t"+ c1 +"\t\t30000");
						System.out.println("恭喜以上用户,获得英雄联盟专属刀妹199皮肤一套!");
						System.out.println("请按任意键退出...");
						String num=input.next();
						continue;
					}else if (xuanze == 2){
						System.out.println("幸运客户是:\n");
						System.out.println("客户编号\t\t客户姓名\t\t客户生日\t客户积分");
						System.out.println("1004\t\t\t"+ d +"\t\t\t"+ d1 +"\t\t10000");
						System.out.println("恭喜以上用户,获得一次和女神进餐的机会!哈哈!");
						System.out.println("请按任意键退出...");
						String num=input.next();
						continue;
					}else if (xuanze == 3){
						System.out.println("今天是"+a+"和"+b+"他们的生日");
						System.out.println("恭喜以上用户,获得本超市提供的欧洲七日游机会!");
						System.out.println("请按任意键退出...");
						String num=input.next();
						continue;
					}else if (xuanze == 4){
						continue dierceng;
					}
					}// 真情回馈界面
					
				}else if (choice2 == 4){
					continue zuiwaiceng;
				}
			}
			
			}//小猫那里的while
			else {
				question++;
				n--;
			    if (question > 2){
				System.out.println("输入错误次数过多,系统即将退出...");
				System.exit(1);
			    }
			    System.out.println("用户名或密码错误,您还有" + n +"次机会重新输入");
			    continue;
			}
		}
		}
		}

	}
}




   总结:1.continue跳出循环时默认跳出距离其最近的一个循环,若想跳出一个以上的循环,则在循环前给循环定义一个名字,然后continue 名字,即可。

              2.按任意键退出,即可把任意键理解为任何字符串,所以用String 变量民=input.next()即可。

             

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值