您好,登錄后才能下訂單哦!
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; } } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。