購物系統項目

/**
*
*/
import java.util.Scanner;//導入一個外部的java類
import java.text.SimpleDateFormat;
import java.util.Scanner;//導入一個有關日期的java類
public class Login {
	public static void main(String [] args) {

		String username0 = "admin";
		String password0 = "1111";//定義變量存放默認的用戶名和密碼
		int loginIndex = 0;//定義一個變量,存放用戶登錄的次數
      
		String [] name = new String[10];//定義存放10個客戶姓名的數組變量
        name[0] = "小貓"; 
		name[1] = "小狗";
		name[2] = "小馬";
		name[3] = "小狐狸";
		name[4] = "大象";
		
		int [] number = new int[10];//定義一個存放10個客戶編號的數組變量
		number[0] = 1001;
		number[1] = 1002;
		number[2] = 1003;
		number[3] = 1004;
		number[4] = 1005;
		
		String [] birthday = new String[10];//定義一個存放10個客戶出生年月日的數組變量
        birthday[0] = "1992-07-10";
        birthday[1] = "1992-06-17";
        birthday[2] = "1992-07-10";
		birthday[3] = "1992-11-01";
		birthday[4] = "1992-11-17";
		String [] date = new String[5];//定義一個存放客戶生日的數組變量
		date[0] = "07-10";
		date[1] = "06-17";
		date[2] = "07-10";
		date[3] = "11-01";
		date[4] = "11-17";
		
       int [] num = new int[10];//定義一個存放10個客戶積分的數組變量
        num[0] = 20000;
        num[1] = 25000;
		num[2] = 30000;
		num[3] = 10000;
        num[4] = 10000;
		
		first:
		while(true) {//用於返回上一級
			//展示登錄菜單
		    System.out.println("\t\t\t歡迎使用我行我素購物管理系統1.0版");
		    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
		    System.out.println("\t\t\t1.登錄系統");
		    System.out.println("\t\t\t2.更改管理員密碼");
		    System.out.println("\t\t\t3.退出");
            System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");

		    //提示用戶輸入選項
		    System.out.print("請輸入您的選擇:");
		    Scanner input = new Scanner(System.in);

			second:
		    while(true){//輸入上面選項的循環
		        int choice1 = input.nextInt();
		        //判斷用戶輸入選項是否正確

		        if(choice1 == 1) {/*登錄系統*/

                    /*用戶輸入登錄,如果登錄失敗,繼續重新登錄,失敗次數超過三次,退出系統*/
					third:
					while(true) {
					    //登錄系統要實現的功能:提示用戶輸入用戶名和密碼
				        System.out.println("請輸入用戶名:");
					    String username = input.next();
					    System.out.println("請輸入密碼:");
					    String password = input.next();

					    //判斷用戶輸入的用戶名是否admin,密碼是否1111
					    /*整數判斷可以用==;字符串是否相等用equals*/
                        if((username0).equals(username)&&(password0).equals(password)) {
							System.out.println("登錄成功!");
							break;//退出循環
					    } else {
						    loginIndex ++;
                            if(loginIndex > 2) {
								System.out.println("輸入次數超過三次;系統即將退出...");
								System.exit(1);
							}
                            System.out.println("您輸入的用戶名和密碼錯誤,您還有" + (3 - loginIndex) + "次機會重新輸入");
						} 
					}//登錄成功

					fourth:
					while(true){
              
					    System.out.println("\t\t\t歡迎使用我行我素購物管理系統");
					    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
					    System.out.println("\t\t\t1.客戶信息管理");
					    System.out.println("\t\t\t2.購物結算");
					    System.out.println("\t\t\t3.真情回饋");
					    System.out.println("\t\t\t4.返回上一級");
                        System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
					    System.out.println("請輸入您的選擇:");

                        fifth:
					    while(true) {//對用戶輸入的選項的判斷
					        int choice2 = input.nextInt();
                            
      				        if(choice2 == 1) {//客戶信息管理

								sixth:
								while(true) {
									int choice3;
									System.out.println("我行我素購物管理系統 > 客戶信息管理");
									System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
									System.out.println("\t\t\t1.顯示所有客戶信息");
									System.out.println("\t\t\t2.添加客戶信息");
									System.out.println("\t\t\t3.修改客戶信息");
									System.out.println("\t\t\t4.查詢客戶信息");
                                    System.out.println("\t\t\t5.返回上一級");
                                    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
									System.out.println("請輸入您的選擇:");

                                    seventh:
								    while(true) {//對輸入選項的判斷

								        choice3 = input.nextInt();


								        if(choice3 == 1) {//顯示所有客戶信息
									        System.out.println("客戶編號\t\t客戶姓名\t\t客戶生日\t\t客戶積分");
										   
										    for(int i = 0;i <= name.length;i++) {
											    System.out.println(number[i] + "\t\t" + name[i] + "\t\t" + birthday[i] + "\t\t" + num[i]);
										    }
											break;


								        } else if(choice3 == 2) {//添加客戶信息
										     
										    System.out.println("歡迎添加客戶!");
										    System.out.println("請輸入新客戶的名稱(2-8個字符):");
									        String newname = input.next();
										    System.out.println("請輸入新客戶的生日(格式:yyyy-mm-dd):");
										    String newbirthday = input.next();
											System.out.println("請輸入新客戶的積分:");
											int newnum = input.nextInt();
											System.out.println("添加成功!");
											break fifth;

								        } else if(choice3 == 3) {//修改客戶信息
											System.out.println("請輸入你要修改的客戶編號:");

                                            int number0 = input.nextInt();
											for(int k = 1;k <= number.length;k++){
												if(number0 == number[k]){
                                                     System.out.println("客戶編號\t\t客戶姓名\t\t客戶生日\t\t客戶積分");
										             System.out.println(number[k] + "\t\t" + name[k] + "\t\t" + birthday[k] + "\t\t" + num[k]);
												}
                                                System.out.println("請選擇你要修改的內容:1.姓名\t\t2.生日");
												System.out.println("請輸入你的選擇:");
                                                int choose = input.nextInt();
												if(choose == 1){
													System.out.println("請輸入新的客戶名稱:");
                                                    String newname0 = input.next();
													System.out.println("修改成功");
													
												}else if(choose == 2){
													System.out.println("請輸入新的客戶生日:");
													String newbirthday0 = input.next();
													System.out.println("修改成功");
												}
												}
									        break fifth;

											
								        } else if(choice3 == 4) {//查詢客戶信息
                                            System.out.println("請輸入你要查詢的客戶編號:");
                                            int number1 = input.nextInt();
											for(int j = 1;j <= number.length;j++){
												if(number1 == number[j]){
                                                     System.out.println("客戶編號\t\t客戶姓名\t\t客戶生日\t\t客戶積分");
										             System.out.println(number[j] + "\t\t" + name[j] + "\t\t" + birthday[j] + "\t\t" + num[j]);
												}
												else{
													System.out.println("你要查詢的客戶編號不存在:");

												}
												break;
											}
								           
											break;
								        } else if(choice3 == 5) {
									        //返回上一級
											break fifth;
								        } else {
										    System.out.println("輸入有誤,請重新輸入!");
									    }
								    }//循環結束
									if(choice3 != 5) {
                                        System.out.println("請輸入任意鍵繼續:");
										break ;
									}
						        }//循環結束
								break fifth;

					        } else if(choice2 == 2) {//購物結算
							    System.out.println("歡迎進入購物系統!");
							    System.out.println("請輸入您的客戶編號:");
								String name1 = null;
								int y = 0;
								while(true){
                                    y = 0;
							        int number1 = input.nextInt();
								    while(true){
									    if(number1 == number[y]) {
										    name1 = name[y];
										    break;
									    }
									    y++;
									    if(y > number.length){
										    System.out.println("您輸入的標號錯誤,請重新輸入!");
										    break;
									    }
								    }
									if(y <= number.length){
										break;
									}
								}
                                System.out.println("商城現有商品如下:");
						        System.out.println("商品編號\t\t商品名稱\t\t商品價格");
						        System.out.println("1\t\t\t雲南白藥\t\t¥18.00");
						        System.out.println("2\t\t\t小米手機\t\t¥1,998.00");
						        System.out.println("3\t\t\t小黑\t\t\t¥4,998.00");
                                System.out.println("4\t\t\t拖鞋\t\t\t¥25.80");
                                System.out.println("5\t\t\t醬油\t\t\t¥5.60");
						        System.out.println("6\t\t\t汽車模型\t\t¥350.00");
						        System.out.println("7\t\t\t坦克模型\t\t¥400.00");
						        System.out.println("8\t\t\t玩具槍\t\t¥99.80");
                                System.out.print("請輸入您要購買的產品編號:");
						        int choice4 = input.nextInt();
						        System.out.print("請輸入您要購買的產品數量:");
						        int choice5 = input.nextInt();
						        double sum = 0;
						        double a = 0;
						        String str = null;
						        switch (choice4) {
									case 1:
							            sum = choice5 * 18;
						                a = 18;
						                str = "雲南白藥";
                                        break;
						            case 2:
							            sum = choice5 * 1998;
						                a = 1998;
						                str = "小米手機";
						                break;
						            case 3:
							            sum = choice5 * 4998;
						                a = 4998;
						                str = "小黑";
						                break;
						            case 4:
							            sum = choice5 * 25.8;
						                a = 25.8;
						                str = "拖鞋";
						                break;
						            case 5:
							            sum = choice5 * 5.6;
						                a = 5.6;
						                str = "醬油";
						                break;
						            case 6:
							            sum = choice5 * 350;
						                a = 350;
						                str = "汽車模型";
						                break;
						            case 7:
							            sum = choice5 * 400;
						                a = 400;
						                str = "坦克模型";
						                break;
						            case 8:
							            sum = choice5 * 99.8;
						                a = 99.8;
						                str = "玩具槍";
						                break;
						            default:
							            break;
						        }        
						        System.out.println("尊敬的用戶:" + name1);
						        System.out.println("產品名稱\t\t產品單價\t\t購買數量");
						        System.out.println(str + "\t\t" + a +"\t\t\t" + choice5);
						        System.out.println("您購買的產品總價爲:¥" + sum);
						        System.out.println("按您當前的積分,您的折扣是:0.85");
			                    double b;
				                b = 0.85 * sum;
				                System.out.println("您的應付款爲:¥" + (float)b);
								System.out.print("請付款:");
					            while(true) {//付款成功的循環
                                    int x = input.nextInt();
                                    if(x < sum){
							            System.out.println("付款錯誤,請重新付款!");
						            } else {
							            System.out.println("付款成功!");
							            System.out.println("找零:¥" + (float)(x - b));
							            System.out.println("歡迎下次光臨!");
									    break;
						            }
							    }//循環結束
								System.out.println("請按任意鍵繼續:");
								String str2 = input.next();
							    break fifth;

					        } else if(choice2 == 3) {/*真情回饋*/
                                one:
								while(true) {
									int choice6;
									System.out.println("我行我素購物管理系統 > 真情回饋");
									System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
									System.out.println("\t\t\t1.幸運大放送");
									System.out.println("\t\t\t2.幸運抽獎");
									System.out.println("\t\t\t3.生日問候");
                                    System.out.println("\t\t\t4.返回上一級");
                                    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
									System.out.println("請輸入您的選擇:");
                                    two:
								    while(true) {//對輸入選項的判斷

								        choice6 = input.nextInt();

								        if(choice6 == 1) {//幸運大放送

										   System.out.println("獲得最高積分的客戶是:");
									       System.out.println("客戶編號\t\t客戶姓名\t\t客戶生日\t\t客戶積分");
										   System.out.println(number[2] + "\t\t" + name[2] + "\t\t" + birthday[2] + "\t\t" + num[2]);
										   System.out.println("恭喜以上用戶,獲得一個價值¥50.00的充值卡");
                                           System.out.println("請按任意鍵繼續:");
										   
									    
									}else if(choice6 ==2 ){//幸運抽獎

										   System.out.println("幸運客戶是:");
									       System.out.println("客戶編號\t\t客戶姓名\t\t客戶生日\t\t客戶積分");
										   System.out.println(number[2] + "\t\t" + name[2] + "\t\t" + birthday[2] + "\t\t" + num[2]);
										   System.out.println("恭喜以上用戶,獲得一個價值¥5,888,00的Iphone5s");
                                           System.out.println("請按任意鍵繼續:");
										  
									      
								
								   }else if(choice6 == 3){//生日問候
                                        String today = "04-09";
									    for(int m = 0;m < birthday.length;m++){
										   if((today).equals(date[m])){
                                                System.out.println("尊敬的客戶,生日快樂!:");
                                                System.out.println("恭喜你獲得生日賀卡!:");
										   }
										   else{
											   System.out.println("對不起,今天沒有過生日的客戶!:");
										   }
										   System.out.println("請按任意鍵繼續!");
										   break ;
										   }
									   									                                          								
							       }else if(choice6 == 4){//返回上一級
									   break fifth;
								   
							       }else{//提示輸入錯誤,重新輸入

								   System.out.println("輸入錯誤,請重新輸入");
								   break;
							       }
								   
							    }
								if(choice6 != 4) {
                                        System.out.println("請輸入任意鍵繼續:");
										continue  ;
								}
								
							}
							
							} else if(choice2 == 4) {//返回上一級
								break second;
					        } else{//提示輸入錯誤,重新輸入
								System.out.println("輸入錯誤,請重新輸入");
								break;
					        }
						}
				    }//輸入選項的循環

		        } else if(choice1 == 2) {/*更改管理員密碼*/
				while(true) {
					System.out.println("請輸入用戶名:");
					String usename = input.next();
					System.out.println("請輸入密碼:");
					String password = input.next();
			            if((username0).equals(usename)&&(password0).equals(password)) {
						
							System.out.println("請輸入新密碼:");
							String newname = input.next();
							System.out.println("請確認新密碼:");
							String newpass = input.next();
							   if(newname.equals(newpass)){
								   System.out.println("恭喜你,修改密碼成功!");
								   System.out.println("按任意鍵繼續");
							   } 
						
					    } else {
						    loginIndex ++;
                            if(loginIndex > 2) {
								System.out.println("輸入次數超過三次;系統即將退出...");
								System.exit(1);
							}
                            System.out.println("您輸入的用戶名和密碼錯誤,您還有" + (3 - loginIndex) + "次機會重新輸入");
						} 
						break second;
					}//修改密碼成功
					
					
 
		        } else if(choice1 == 3) {/*退出系統*/
				    System.out.println("系統即將退出....");
					System.exit(1);
		        } else {/*提示用戶輸入錯誤,請重新輸入*/
		            System.out.println("輸入有誤,請重新輸入:");
		        }
	        }//輸入選項的循環
        }//登錄菜單
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章