我行我素购物管理系统

项目结构

Customer类

 1 package com.wxws.sms.data;
 2 /**
 3  * 会员类
 4  *
 5  */
 6 public class Customer {
 7      public int  custNo;        //会员编号  
 8      public String  custBirth; //会员生日
 9      public int  custScore ; //会员积分
10       
11 }

Data类

 1 package com.wxws.sms.data;
 2 
 3 /**
 4  * 初始化数据
 5  */
 6 public class Data {
 7     /* 商品信息 */
 8     public Goods goods[] = new Goods[50];
 9     /* 会员信息 */
10     public Customer customers[] = new Customer[100];
11     /* 管理员 */
12     public Manager manager = new Manager();
13 
14     public void ini() {
15         for (int i = 0; i < goods.length; i++) {
16             goods[i] = new Goods();
17         }
18         
19         // 商品0
20         goods[0].goodsName = "addidas运动鞋";
21         goods[0].goodsPrice = 880;
22         
23         // 商品1
24         goods[1].goodsName = "Kappa网球裙";
25         goods[1].goodsPrice = 200;
26     
27         // 商品2
28         goods[2].goodsName = "网球拍";
29         goods[2].goodsPrice = 780;
30     
31 
32         // 商品3
33         goods[3].goodsName = "addidasT恤";
34         goods[3].goodsPrice = 420.78;
35         
36 
37         // 商品4
38         goods[4].goodsName = "Nike运动鞋";
39         goods[4].goodsPrice = 900;
40         
41 
42         // 商品5
43         goods[5].goodsName = "Kappa网球";
44         goods[5].goodsPrice = 45;
45         
46 
47         // 商品6
48         goods[6].goodsName = "KappaT恤";
49         goods[6].goodsPrice = 245;
50 
51     
52         for (int i = 0; i < customers.length; i++) {
53             customers[i] = new Customer();
54         }
55         customers[0].custNo = 1900; // 客户1
56         customers[0].custBirth = "08/05";
57         customers[0].custScore = 2000;
58 
59         customers[1].custNo = 1711; // 客户2
60         customers[1].custBirth = "07/13";
61         customers[1].custScore = 4000;
62 
63         customers[2].custNo = 1623; // 客户3
64         customers[2].custBirth = "06/26";
65         customers[2].custScore = 5000;
66 
67         customers[3].custNo = 1545; // 客户4
68         customers[3].custBirth = "04/08";
69         customers[3].custScore = 2200;
70 
71         customers[4].custNo = 1464; // 客户5
72         customers[4].custBirth = "08/16";
73         customers[4].custScore = 1000;
74 
75         customers[5].custNo = 1372; // 客户6
76         customers[5].custBirth = "12/23";
77         customers[5].custScore = 3000;
78 
79         customers[6].custNo = 1286; // 客户7
80         customers[6].custBirth = "12/21";
81         customers[6].custScore = 10080;
82 
83     }
84 
85 }

Gift类

 1 package com.wxws.sms.data;
 2 /**
 3  * Gift.java
 4  * 礼品类
 5  */
 6 public class Gift {
 7      public String name;
 8      public double price;
 9      
10      public String toString(){
11          return "一个价值¥" + price + "的" + name;
12      }
13 }

Goods类

 1 package com.wxws.sms.data;
 2 /**
 3  * 商品类
 4  *
 5  */
 6 public class Goods {
 7     public String goodsName;
 8     public double goodsPrice;
 9     
10 }

Manager类

 1 package com.wxws.sms.data;
 2 
 3 public class Manager {
 4        /**
 5         * 管理员信息
 6         */       
 7        public String username = "manager";  //管理员名字
 8        public String password = "0000";     //管理员密码
 9          
10 }

CustManagement类

  1 package com.wxws.sms.management;
  2 
  3 import java.util.Scanner;
  4 
  5 import com.wxws.sms.data.Customer;
  6 import com.wxws.sms.data.Goods;
  7 
  8 public class CustManagement {
  9     /* 商品信息 */
 10     public Goods goods[] = new Goods[50];
 11     /* 会员信息 */
 12     public Customer customers[] = new Customer[100];
 13 
 14     /**
 15      * 传递数据库
 16      */
 17     public void setData(Goods[] goods, Customer[] customers) { // 如果不使用this,请把形参名改变即可
 18         this.goods = goods;
 19         this.customers = customers;
 20     }
 21 
 22     /**
 23      * 返回上一级菜单
 24      */
 25     public void returnLastMenu() {
 26         System.out.print("\n\n请按'n'返回上一级菜单:");
 27         Scanner input = new Scanner(System.in);
 28         boolean con = true;
 29         do {
 30             if (input.next().equals("n")) {
 31                 Menu menu = new Menu();
 32                 menu.setData(goods, customers);
 33                 menu.showCustMMenu();
 34             } else {
 35                 System.out.print("输入错误, 请重新'n'返回上一级菜单:");
 36                 con = false;
 37             }
 38         } while (!con);
 39     }
 40 
 41     /**
 42      * 循环增加会员:MY
 43      */
 44     public void add() {
 45         System.out.println("我行我素购物管理系统 > 客户信息管理 > 添加客户信息\n\n");
 46         String con = "n";
 47         // 确定插入会员位置
 48         int index = -1;
 49         for (int i = 0; i < customers.length; i++) {
 50             if (customers[i].custNo == 0) {
 51                 index = i;
 52                 break;
 53             }
 54         }
 55 
 56         do { // 循环录入会员信息
 57             Scanner input = new Scanner(System.in);
 58             System.out.print("请输入会员号(<4位整数>):");
 59             int no = input.nextInt();
 60             System.out.print("请输入会员生日(月/日<用两位数表示>):");
 61             String birth = input.next();
 62             System.out.print("请输入积分:");
 63             int score = input.nextInt();
 64 
 65             // 会员号无效则跳出
 66             if (no < 1000 || no > 9999) {
 67                 System.out.println("客户号" + no + "是无效会员号!");
 68                 System.out.println("录入信息失败\n");
 69                 System.out.println("继续添加会员吗?(y/n)");
 70                 con = input.next();
 71                 continue;
 72             }
 73             // 添加会员
 74 
 75             customers[index].custNo = no;
 76             customers[index].custBirth = birth;
 77             customers[index++].custScore = score;
 78             System.out.println("新会员添加成功!");
 79             System.out.println("继续添加会员吗?(y/n)");
 80             con = input.next();
 81         } while ("y".equals(con) || "Y".equals(con));
 82         returnLastMenu();
 83     }
 84 
 85     /**
 86      * 更改客户信息
 87      */
 88     public void modify() {
 89         System.out.println("我行我素购物管理系统 > 客户信息管理 > 修改客户信息\n\n");
 90         System.out.print("请输入会员号:");
 91         Scanner input = new Scanner(System.in);
 92         int no = input.nextInt();
 93         System.out.println("  会员号            生日             积分      ");
 94         System.out.println("------------|------------|---------------");
 95         int index = -1;
 96         for (int i = 0; i < customers.length; i++) {
 97             if (customers[i].custNo == no) {
 98                 System.out.println(customers[i].custNo + "\t\t"
 99                         + customers[i].custBirth + "\t\t"
100                         + customers[i].custScore);
101                 index = i;
102                 break;
103             }
104         }
105 
106         if (index != -1) {
107             while (true) {
108                 System.out
109                         .println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
110                 System.out.println("\t\t\t\t1.修 改 会 员 生 日.\n");
111                 System.out.println("\t\t\t\t2.修 改 会 员 积 分.\n");
112                 System.out
113                         .println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
114                 System.out.print("请选择,输入数字:");
115                 switch (input.nextInt()) {
116                 case 1:
117                     System.out.print("请输入修改后的生日:");
118                     customers[index].custBirth = input.next();
119                     System.out.println("生日信息已更改!");
120                     break;
121                 case 2:
122                     System.out.print("请输入修改后的会员积分:");
123                     customers[index].custScore = input.nextInt();
124                     System.out.println("会员积分已更改!");
125                     break;
126                 }
127 
128                 System.out.println("是否修改其他属性(y/n):");
129                 String flag = input.next();
130                 ;
131                 if ("n".equalsIgnoreCase(flag))
132                     break;
133             }
134         } else {
135             System.out.println("抱歉,没有你查询的会员。");
136         }
137 
138         // 返回上一级菜单
139         returnLastMenu();
140 
141     }
142 
143     /**
144      * 查询客户的信息
145      */
146     public void search() {
147         System.out.println("我行我素购物管理系统 > 客户信息管理 > 查询客户信息\n");
148         String con = "y";
149         Scanner input = new Scanner(System.in);
150         while (con.equals("y")) {
151             System.out.print("请输入会员号:");
152             int no = input.nextInt();
153             System.out.println("  会员号            生日             积分      ");
154             System.out.println("------------|------------|---------------");
155             boolean isAvailable = false;
156             for (int i = 0; i < customers.length; i++) {
157                 if (customers[i].custNo == no) {
158                     System.out.println(customers[i].custNo + "\t\t"
159                             + customers[i].custBirth + "\t\t"
160                             + customers[i].custScore);
161                     isAvailable = true;
162                     break;
163                 }
164             }
165             if (!isAvailable) {
166                 System.out.println("抱歉,没有你查询的会员信息。");
167             }
168             System.out.print("\n要继续查询吗(y/n):");
169             con = input.next();
170         }
171 
172         // 返回上一级菜单
173         returnLastMenu();
174     }
175 
176     /**
177      * 显示所有的会员信息
178      */
179     public void show() {
180         System.out.println("我行我素购物管理系统 > 客户信息管理 > 显示客户信息\n\n");
181         System.out.println("  会员号            生日             积分      ");
182         System.out.println("------------|------------|---------------");
183         int length = customers.length;
184         for (int i = 0; i < length; i++) {
185             if (customers[i].custNo == 0) {
186                 break; // 客户信息已经显示完毕
187             }
188             System.out.println(customers[i].custNo + "\t\t"
189                     + customers[i].custBirth + "\t\t" + customers[i].custScore);
190         }
191 
192         // 返回上一级菜单
193         returnLastMenu();
194     }
195     /**
196      * 
197      * @param ageline
198      */
199     public void AgeRate(int ageline){
200         int young = 0;    //记录年龄分界线以下顾客的人数
201         int old = 0; //记录年龄分界线以上顾客的人数
202         int age = 0;    //保存顾客的年龄
203         Scanner input = new Scanner(System.in);
204         for(int i = 0; i < 10; i++){
205             System.out.print("请输入第" +(i+1)+ "位顾客的年龄:");
206             age = input.nextInt();
207             if(age > 0 && age <= 30){
208                 young++;
209             }
210         }
211         System.out.println("30岁以下的比例是:" + young/10.0*100 +"%");
212         System.out.println("30岁以上的比例是:" + (1-young/10.0)*100 +"%");
213     }
214 }

GiftManagement类

  1 package com.wxws.sms.management;
  2 
  3 import java.util.Scanner;
  4 import com.wxws.sms.data.*;
  5 
  6 /**
  7  *真情回馈
  8  */
  9 public class GiftManagement {
 10     /* 商品信息 */
 11     public Goods goods[] = new Goods[50];
 12     /* 会员信息 */
 13     public Customer customers[] = new Customer[100];
 14     
 15       /**
 16        * 传递数据库
 17        */
 18     public void setData(Goods[] goods,  Customer[] customers){ //如果不使用this,请把形参名改变即可
 19         this.goods = goods; 
 20         this.customers = customers;
 21     }
 22        
 23     
 24     /**
 25      * 返回上一级菜单
 26      */
 27       public void returnLastMenu(){
 28            System.out.print("\n\n请按'n'返回上一级菜单:");
 29            Scanner input = new Scanner(System.in);
 30            boolean con = true;
 31            do{ 
 32              if(input.next().equals("n")){
 33                 Menu menu = new Menu();
 34                 menu.setData(goods,customers);
 35                 menu.showSendGMenu();
 36              }else{
 37                 System.out.print("输入错误, 请重新'n'返回上一级菜单:");
 38                 con = false;
 39              }
 40            }while(!con);
 41        }
 42     
 43     /**
 44       * 实现生日问候功能
 45       */
 46       public void sendBirthCust(){
 47           System.out.println("我行我素购物管理系统 > 生日问候\n\n");
 48           System.out.print("请输入今天的日期(月/日<用两位表示>):");
 49           Scanner input = new Scanner(System.in);
 50           String date = input.next();
 51           System.out.println(date);
 52           String no = "";
 53           boolean isAvailable = false;
 54           for(int i = 0; i < customers.length; i++){
 55                if(customers[i].custBirth!=null && customers[i].custBirth.equals(date)){
 56                  no = no + customers[i].custNo + "\n";
 57                  isAvailable = true;
 58                }
 59           }
 60           if(isAvailable){
 61                 System.out.println("过生日的会员是:");
 62                 System.out.println(no);
 63              System.out.println("恭喜!获赠MP3一个!");
 64           }else{
 65                 System.out.println("今天没有过生日的会员!");
 66           }     
 67           
 68           //返回上一级菜单
 69           returnLastMenu();
 70       }
 71       
 72       /**
 73        *  产生幸运会员
 74        */
 75       public void  sendLuckyCust(){
 76           System.out.println("我行我素购物管理系统 > 幸运抽奖\n\n");
 77           System.out.print("是否开始(y/n):");
 78           Scanner input = new Scanner(System.in);
 79           if(input.next().equals("y")){
 80               int random = (int)(Math.random()* 10);
 81               //System.out.println(random);
 82               int baiwei; //百位 
 83               boolean isAvailable = false;
 84               String list = "";
 85               for(int i = 0; i< customers.length; i++){
 86                  if(customers[i].custNo==0){
 87                      break;
 88                  } 
 89                  baiwei = customers[i].custNo / 100 % 10;
 90                  if(baiwei == random){
 91                      list = list + customers[i].custNo+ "\t";
 92                      isAvailable = true;
 93                  }
 94               }
 95               if(isAvailable){
 96                    System.out.println("幸运客户获赠MP3:" + list);
 97               }else{
 98                    System.out.println("无幸运客户。");
 99               }
100           }
101           
102           //返回上一级菜单
103           returnLastMenu();
104       }
105       /**
106        * 幸运大放送
107        */
108       public void sendGoldenCust(){
109           System.out.println("我行我素购物管理系统 > 幸运大放送\n\n");
110           int index = 0;
111           int max = customers[0].custScore;
112           //假定积分各不相同
113           for(int i = 0; i < customers.length; i++){
114               if(customers[i].custScore == 0){
115                   break;  //数组后面为空用户
116               }
117               //求最大积分的客户
118               if(customers[i].custScore  > max){
119                   max = customers[i].custScore ;
120                   index = i;
121               }
122           }
123           System.out.println("具有最高积分的会员是: " + customers[index].custNo + "\t" + customers[index].custBirth + "\t" + customers[index].custScore);
124           //创建笔记本电脑对象
125           Gift laptop = new Gift();
126           laptop.name = "苹果笔记本电脑";
127           laptop.price = 12000;
128           System.out.print("恭喜!获赠礼品: ");
129           System.out.println(laptop);
130           
131           //返回上一级菜单
132           returnLastMenu();
133       }
134 }

Menu类

  1 package com.wxws.sms.management;
  2 
  3 import java.util.Scanner;
  4 import com.wxws.sms.data.*;
  5 
  6 /**
  7  *Menu.java
  8  *菜单类 
  9  */
 10 public class Menu {
 11  
 12     /* 商品信息 */
 13     public Goods goods[] = new Goods[50];
 14     /* 会员信息 */
 15     public Customer customers[] = new Customer[100];
 16     
 17       /**
 18        * 传递数据库
 19        */
 20     public void setData(Goods[] goods,  Customer[] customers){ //如果不使用this,请把形参名改变即可
 21         this.goods = goods; 
 22         this.customers = customers;
 23     }
 24     
 25     /**
 26      * 显示我行我素购物管理系统的登录菜单
 27      */
 28     public void showLoginMenu() {
 29         System.out.println("\n\n\t\t\t    欢迎使用我行我素购物管理系统\n\n");
 30         System.out.println ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
 31         System.out.println("\t\t\t\t 1. 登 录 系 统\n\n");
 32         System.out.println("\t\t\t\t 2. 更 改 管 理 员 密 码\n\n");
 33         System.out.println("\t\t\t\t 3. 退 出\n\n");
 34         System.out.println ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
 35         System.out.print("请选择,输入数字:");    
 36     }    
 37     
 38     /**
 39      * 显示我行我素购物管理系统的主菜单
 40      */
 41     public void showMainMenu() {
 42         System.out.println("\n\n\t\t\t\t欢迎使用我行我素购物管理系统\n");
 43         System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
 44         System.out.println("\t\t\t\t 1. 客 户 信 息 管 理\n");
 45         System.out.println("\t\t\t\t 2. 购 物 结 算\n");
 46         System.out.println("\t\t\t\t 3. 真 情 回 馈\n");        
 47         System.out.println("\t\t\t\t 4. 注 销\n");
 48         System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
 49         System.out.print("请选择,输入数字:");
 50         
 51         Scanner input = new Scanner(System.in);
 52         boolean con = false;
 53         do{
 54             String num = input.next();
 55               if(num.equals("1")){
 56                    //显示客户信息管理菜单
 57                    showCustMMenu();
 58                    break;
 59               }else if(num.equals("2")){
 60                    //显示购物结算菜单
 61                    Pay pay = new Pay();
 62                    pay.setData(goods,customers);
 63                    pay.calcPrice();
 64                    break;
 65               }else if(num.equals("3")){
 66                    //显示真情回馈菜单
 67                    showSendGMenu();
 68                    break;
 69               }else if(num.equals("4")){
 70                    showLoginMenu(); 
 71                    break;
 72               }else{
 73                    System.out.print("输入错误,请重新输入数字:");
 74                    con = false;
 75               }
 76         }while(!con);
 77     }
 78     
 79     /**
 80      * 客户信息管理菜单
 81      */
 82     
 83     public void showCustMMenu() {
 84         System.out.println("我行我素购物管理系统 > 客户信息管理\n");
 85         System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
 86         System.out.println("\t\t\t\t 1. 显 示 所 有 客 户 信 息\n");
 87         System.out.println("\t\t\t\t 2. 添 加 客 户 信 息\n");
 88         System.out.println("\t\t\t\t 3. 修 改 客 户 信 息\n");
 89         System.out.println("\t\t\t\t 4. 查 询 客 户 信 息\n");
 90         System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
 91         System.out.print("请选择,输入数字或按'n'返回上一级菜单:");
 92         Scanner input = new Scanner(System.in);
 93         
 94         boolean con = true;  //处理如果输入菜单号错误
 95         do{
 96           CustManagement cm = new CustManagement();
 97           cm.setData(goods,customers);
 98           String num = input.next();
 99           if(num.equals("1")){
100               cm.show();
101               break;
102           }else if(num.equals("2")){
103               cm.add();
104               break;
105           }else if(num.equals("3")){
106               cm.modify();
107               break;
108           }else if(num.equals("4")){
109               cm.search();
110               break;
111              
112           }else if(num.equals("n")){
113               showMainMenu();
114               break;
115           }else{
116             System.out.println("输入错误, 请重新输入数字:");
117             con = false;
118           }
119         }while(!con);
120     }
121     
122     /**
123      * 显示我行我素购物管理系统的真情回馈菜单
124      */
125     public void showSendGMenu(){
126          System.out.println("我行我素购物管理系统 > 真情回馈\n");
127          System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
128          System.out.println("\t\t\t\t 1. 幸 运 大 放 送\n");
129          System.out.println("\t\t\t\t 2. 幸 运 抽 奖\n");
130          System.out.println("\t\t\t\t 3. 生 日 问 候\n");
131          System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
132          System.out.print("请选择,输入数字或按'n'返回上一级菜单:");
133          Scanner input = new Scanner(System.in);
134          
135          boolean con = true;  //处理如果输入菜单号错误
136          GiftManagement gm = new GiftManagement();
137          gm.setData(goods,customers);
138             do{
139               String num = input.next();
140               if(num.equals("1")){
141                    //幸运大放送
142                    gm.sendGoldenCust();
143                    break;
144               }else if(num.equals("2")){
145                   //幸运抽奖
146                    gm.sendLuckyCust();
147                    break;
148               }else if(num.equals("3")){
149                   //生日问候
150                   gm.sendBirthCust();
151                   break;
152               }else if(num.equals("n")){
153                   showMainMenu();
154                   break;
155               }else{
156                 System.out.println("输入错误, 请重新输入数字:");
157                 con = false;
158               }
159             }while(!con);
160     }
161 }

Pay类

  1 package com.wxws.sms.management;
  2 
  3 import java.util.*;
  4 
  5 import com.wxws.sms.data.Customer;
  6 import com.wxws.sms.data.Goods;
  7 
  8 public class Pay {
  9     /* 商品信息 */
 10     public Goods goods[] = new Goods[50];
 11     /* 会员信息 */
 12     public Customer customers[] = new Customer[100];
 13 
 14     /**
 15      * 传递数据库
 16      */
 17     public void setData(Goods[] goods, Customer[] customers) { // 如果不使用this,请把形参名改变即可
 18         this.goods = goods;
 19         this.customers = customers;
 20     }
 21 
 22     /**
 23      * 计算客户的折扣数目
 24      */
 25     public double getDiscount(int curCustNo, Customer[] customers) {
 26         double discount;
 27         int index = -1;
 28         for (int i = 0; i < customers.length; i++) {
 29             if (curCustNo == customers[i].custNo) {
 30                 index = i;
 31                 break;
 32             }
 33         }
 34 
 35         if (index == -1) {// 如果会员号不存在
 36             discount = -1;
 37 
 38         } else {
 39 
 40             // 判断折扣
 41             int curscore = customers[index].custScore;
 42             if (curscore < 1000) {
 43                 discount = 0.95;
 44             } else if (1000 <= curscore && curscore < 2000) {
 45                 discount = 0.9;
 46             } else if (2000 <= curscore && curscore < 3000) {
 47                 discount = 0.85;
 48             } else if (3000 <= curscore && curscore < 4000) {
 49                 discount = 0.8;
 50             } else if (4000 <= curscore && curscore < 6000) {
 51                 discount = 0.75;
 52             } else if (6000 <= curscore && curscore < 8000) {
 53                 discount = 0.7;
 54             } else {
 55                 discount = 0.6;
 56             }
 57         }
 58         return discount;
 59 
 60     }
 61 
 62     /*
 63      *  实现购物结算以及输出购物小票
 64      */
 65     public void calcPrice() {
 66         int curCustNo; // 客户号
 67         int goodsNo = 0; // 商品编号
 68         double price; // 商品价格
 69         String name;
 70         int count; // 购入数量
 71         String choice;
 72         String goodsList = ""; // 购物清单
 73         double total = 0; // 购物总金额
 74         double finalPay = 0; // 打折后需付款
 75         double payment; // 实际交费金额
 76 
 77         System.out.println("我行我素购物管理系统 > 购物结算\n\n");
 78 
 79         // 打印产品清单
 80         System.out.println("*************************************");
 81         System.out.println("请选择购买的商品编号:");
 82         for (int i = 0, p = 0; i < goods.length && null != goods[i].goodsName; i++) {
 83             p++;
 84             System.out.println(p + ": " + goods[i].goodsName + "\t");
 85         }
 86         System.out.println("*************************************\n");
 87 
 88         /* 进行购入结算系统 */
 89         Scanner input = new Scanner(System.in);
 90         System.out.print("\t请输入会员号:");
 91         curCustNo = input.nextInt();
 92         double discount = getDiscount(curCustNo, customers);
 93         if (discount == -1) {
 94             System.out.println("会员号输入错误。");
 95         } else {
 96 
 97             do {
 98                 System.out.print("\t请输入商品编号:"); // 数组下标+1即产品编号
 99                 goodsNo = input.nextInt();
100                 System.out.print("\t请输入数目:");
101                 count = input.nextInt();
102 
103                 // 查询单价
104                 price = goods[goodsNo - 1].goodsPrice;
105                 name = goods[goodsNo - 1].goodsName;
106                 total = total + price * count;
107 
108                 // 连接购物清单
109                 goodsList = goodsList + "\n" + name + "\t" + "¥" + price
110                         + "\t\t" + count + "\t\t" + "¥" + (price * count)
111                         + "\t";
112 
113                 System.out.print("\t是否继续(y/n)");
114                 choice = input.next();
115             } while (choice.equals("y"));
116 
117             // 计算消费总金额
118             finalPay = total * discount;
119 
120             // 打印消费清单
121             System.out.println("\n");
122             System.out.println("*****************消费清单*********************");
123             System.out.println("物品\t\t" + "单价\t\t" + "个数\t\t" + "金额\t");
124             System.out.print(goodsList);
125             System.out.println("\n折扣:\t" + discount);
126             System.out.println("金额总计:\t" + "¥" + finalPay);
127             System.out.print("实际交费:\t¥");
128             payment = input.nextDouble();
129             System.out.println("找钱:\t" + "¥" + (payment - finalPay));
130 
131             // 计算获得的积分:
132             int score = (int) finalPay / 100 * 3;
133 
134             // 更改会员积分
135             for (int i = 0; i < customers.length; i++) {
136                 if (customers[i].custNo == curCustNo) {
137                     customers[i].custScore = customers[i].custScore + score;
138                     System.out.println("本次购物所获的积分是: " + score);
139                     break;
140                 }
141             }
142         }
143         // 返回上一级菜单
144         System.out.print("\n请'n'返回上一级菜单:");
145         if (input.next().equals("n")) {
146             Menu menu = new Menu();
147             menu.setData(goods, customers);
148             menu.showMainMenu();
149         }
150 
151     }
152 
153 }

StartSMS类

 1 package com.wxws.sms.management;
 2 
 3 import com.wxws.sms.data.*;
 4 import java.util.*;
 5 
 6 public class StartSMS {
 7       /**
 8        * 我行我素购物管理系统的入口
 9        *
10        */
11       public static void main(String[] args){
12            /*出始化商场的商品和客户信息*/
13            Data initial = new Data();
14            initial.ini();
15            
16            
17            /*进入系统*/
18            Menu menu = new Menu();
19             menu.setData(initial.goods, initial.customers); 
20            menu.showLoginMenu();
21            
22            /*菜单选择*/
23            boolean con = true;
24            while(con){
25              Scanner input = new Scanner(System.in);
26              int choice = input.nextInt();
27              VerifyEqual pv = new VerifyEqual();
28              switch(choice){
29                case 1: 
30                   /*密码验证*/
31                   for(int i = 3; i>=1; i--){
32                       if(pv.verify(initial.manager.username, initial.manager.password)){
33                           menu.showMainMenu();
34                           break;
35                       }else if(i!=1){
36                           System.out.println("\n用户名和密码不匹配,请重新输入:"); //超过3次输入,退出
37                       }else{
38                           System.out.println("\n您没有权限进入系统!谢谢!");
39                           con = false;
40                       }
41                   }
42                   break;
43                case 2: 
44                   if(pv.verify(initial.manager.username, initial.manager.password)){
45                       System.out.print("请输入新的用户名:");
46                       String name = input.next();
47                       System.out.print("请输入新的密码:");
48                       String pwd = input.next();
49                     
50                       System.out.print("请再次输入新的密码:");
51                       String repwd = input.next();
52                       if(pwd.equals(repwd)){
53                           initial.manager.username = name;
54                           initial.manager.password = pwd;
55                           System.out.println("用户名和密码已更改!");  
56                       }
57                       else{
58                           System.out.println("两次密码不一致。");
59                       }
60                           
61                       System.out.println("\n请选择,输入数字:");
62                   }else{
63                       System.out.println("抱歉,你没有权限修改!");
64                       con = false;
65                   }
66                   break;
67                case  3: 
68                   System.out.println("谢谢您的使用!");
69                   con = false;
70                   break;
71                default: 
72                   System.out.print("\n输入有误!请重新选择,输入数字: ");
73              }
74              if(!con){
75                  break;
76              }
77            }
78           
79       }
80 }

VerifyEqual类

 1 package com.wxws.sms.management;
 2 import java.util.*;
 3 public class VerifyEqual {
 4     /**
 5      * 验证管理员的用户名和密码是否相等
 6      */ 
 7     public boolean verify(String username, String password){
 8           System.out.print("请输入用户名:");
 9           Scanner input = new Scanner(System.in);
10           String name = input.next();
11           System.out.print("请输入密码:");
12           input = new Scanner(System.in);
13           String psw = input.next();
14           if(name.equals(username) && password.equals(psw)){
15               return true;
16           }else{
17               return false;
18           }
19      }
20 }

以上仅供参考哟~_~

posted @ 2018-07-12 19:03  久孤丶  阅读(3426)  评论(1编辑  收藏  举报