/*
* @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
}
}
}