用java写我行我素购物系统
import java.util.Scanner; public class 管理员 { String name; String oldpsw; String newpsw; String repsw; Scanner input=new Scanner(System.in); public void Change(){ System.out.println("请输入用户名:"); String inputname=input.next(); System.out.println("请输入密码:"); String inputpsw=input.next(); if(inputname.equals(name)&&inputpsw.equals(oldpsw)){ System.out.println("请输入新密码"); newpsw=input.next(); System.out.println("请再次输入密码"); repsw=input.next(); if(newpsw.equals(repsw)){ System.out.println("密码修改成功!"); oldpsw=newpsw; } while(!(newpsw.equals(repsw))){ System.out.println("密码输入错误,请重新输入!"); System.out.println("请输入您的新密码:"); newpsw=input.next(); System.out.println("请再次输入新密码"); repsw=input.next(); } System.out.println("密码修改成功!"); } else{ System.out.println("您的账号密码输入有误,请重新输入!"); } } public void show(){ System.out.println("名称"+"\t\t价格"); System.out.println("可乐330ml"+"\t3元"); System.out.println("雪碧330ml"+"\t3元"); System.out.println("电饭锅"+"\t\t300元"); } public void pay(){ String name = ""; double price = 0.0; int goodsNo = 0; int amount = 0; double discount = 0.8; double total = 0.0; double payment = 0.0; System.out.println("*******************************************"); System.out.println("请选择购买的商品编号:"); System.out.println("1.可乐 2.雪碧 3.电饭锅"); System.out.println("*******************************************"); String answer = "y"; while("y".equals(answer)){ System.out.print("\n请输入商品编号:"); goodsNo = input.nextInt(); switch(goodsNo){ case 1: name = "可乐"; price = 3; break; case 2: name = "雪碧"; price = 3; break; case 3: name = "电饭锅"; price = 300; break; } System.out.print("请输入购买数量:"); amount = input.nextInt(); System.out.println(name+ "¥" + price +"\t数量 " + amount + "\t合计 ¥" + price*amount); total += price*amount; System.out.print("是否继续(y/n)"); answer = input.next(); } System.out.println("\n折扣:" + discount); System.out.println("应付金额:" +total*discount); System.out.print("实付金额:"); payment = input.nextDouble(); while(payment - total*discount < 0){ System.out.print("您输入的金额小于应付金额,请重新输入:"); payment = input.nextDouble(); } System.out.println("找钱:" + (payment - total*discount)); } public void xingyun(){ int random = (int) (Math.random() * 10); System.out.println("我行我素购物管理系统 > 幸运抽奖\n"); System.out.print("请输入4位会员号: "); int custNo = input.nextInt(); int baiwei = custNo / 100 % 10; if (baiwei == random) { System.out.println(custNo + "是幸运客户,获精美Mp3一个。"); } else { System.out.println(custNo + " 谢谢您的支持!"); } } public void huangou(){ System.out.print("请输入消费金额:"); double money = input.nextDouble(); double extra = 0; int choice = 0; if(money>=50){ System.out.println("是否参加优惠换购活动:"); System.out.println("1:满50元,加2元换购百事可乐饮料1瓶"); System.out.println("2:满100元,加3元换购500ml可乐一瓶"); System.out.println("3:满100元,加10元换购5公斤面粉"); System.out.println("4:满200元,加10元可换购1个苏泊尔炒菜锅"); System.out.println("5:满200元,加20元可换购欧莱雅爽肤水一瓶"); System.out.println("0:不换购"); System.out.print("请选择:"); if(input.hasNextInt()==true){ choice = input.nextInt(); switch(choice){ case 1: if(money>=50){ extra = 2; } break; case 2: if(money>=100){ extra = 3; } break; case 3: if(money>=100){ extra = 10; } break; case 4: if(money>=200){ extra = 10; } break; case 5: if(money>200){ extra = 20; } break; default: break; } }else{ System.out.println("请输入正确的数字!"); } } double total = money + extra; System.out.println("本次消费总金额:"+ total); if(choice == 1){ System.out.println("成功换购:" + "百事可乐饮料1瓶。"); }else if(choice ==2 ){ System.out.println("成功换购:" + "500ml可乐一瓶。"); }else if(choice == 3){ System.out.println("成功换购:" + "5公斤面粉。"); }else if(choice == 4){ System.out.println("成功换购:" + "1个苏泊尔炒菜锅。"); }else if(choice == 5){ System.out.println("成功换购:" + "欧莱雅爽肤水一瓶。"); }else { System.out.println("无换购项目!"); } } }
import java.util.Scanner; public class 主体 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub 管理员 XG=new 管理员(); Scanner input=new Scanner(System.in); String account="TOM"; String pwd="123"; System.out.println("请选择!"); System.out.println("1.登录我行我素管理系统"); System.out.println("2.修改管理员密码"); int KS=input.nextInt(); switch(KS){ case 1:System.out.println("请输入您的账号"); String A=input.next(); System.out.println("请输入您的密码"); String B=input.next(); if(account.equals(A)&&pwd.equals(B)){ System.out.println("登录成功!"); System.out.println("欢迎进入我行我素~~"); System.out.println("***************************"); System.out.println("请选择您的选项"); System.out.println("****************************"); System.out.println("1.查询商品价格"); System.out.println("2.购物结算计算"); System.out.println("3.幸运抽奖"); System.out.println("4.商品换购"); int F=input.nextInt(); switch(F){ case 1: XG.show(); break; case 2: XG.pay(); break; case 3: XG.xingyun(); break; case 4: XG.huangou(); } } else{ System.out.println("账号密码错误,请重新输入!"); } break; case 2: XG.name="TOM"; XG.oldpsw="123"; XG.Change(); break; } } }
网站名称:用java写我行我素购物系统
文章转载:http://azwzsj.com/article/ppehgj.html