CustomerView
1 public class CustomerView{
2 private CustomerList customerList = new CustomerList(10);
3 private static boolean loopFlag=true;
4 private static CMUtility cm=new CMUtility();
5 private static CustomerView cv=new CustomerView();
6
7 public void enterMainMenu(){
8 char select=cm.readMenuSelection();
9 switch (select) {
10 case '1':
11 cv.addNewCustomer();
12 break;
13 case '2':
14 cv.modifyCustomer();
15 break;
16 case '3':
17 cv.deleteCustomer();
18 break;
19 case '4':
20 cv.listAllCustomers();
21 break;
22 case '5':
23 cv.exit();
24 break;
25 }
26 }
27
28 private void addNewCustomer(){
29 Customer c=new Customer();
30 System.out.println("---------------------添加客户---------------------");
31 System.out.print("姓名:");
32 c.setName(cm.readString(100));
33
34 System.out.print("性别:");
35 c.setGender(cm.readChar());
36
37 System.out.print("年龄:");
38 c.setAge(cm.readInt());
39
40 System.out.print("电话:");
41 c.setPhone(cm.readString(100));
42
43 System.out.print("邮箱:");
44 c.setEmail(cm.readString(100));
45 customerList.addCustomer(c);
46 System.out.println("---------------------添加完成---------------------");
47 }
48
49 private void modifyCustomer(){
50
51 }
52
53 private void deleteCustomer(){
54 customerList.deleteCustomer(cm.readInt());
55 }
56
57 private void listAllCustomers(){
58 Customer[] cu=customerList.getAllCustomers();
59 System.out.println("---------------------客户列表---------------------");
60 System.out.println("编号\t姓名\t性别\t年龄\t电话\t\t邮箱");
61 for (int i=0,counts=1;i<cu.length;i++) {
62 if(cu[i].getName()!=null){
63 System.out.print(counts+"\t");
64 System.out.print(cu[i].getName()+"\t");
65 System.out.print(cu[i].getGender()+"\t");
66 System.out.print(cu[i].getAge()+"\t");
67 System.out.print(cu[i].getPhone()+"\t");
68 System.out.println(cu[i].getEmail()+"\t");
69 counts++;
70 }
71 }
72 System.out.println("-------------------客户列表完成--------------------");
73 }
74 private void exit(){
75 System.out.print("确认是否退出:");
76 char exit=cm.readConfirmSelection();
77 if(exit=='Y'){
78 loopFlag=false;
79 }
80 }
81
82 public static void main(String[] args){
83 while(loopFlag){
84 printMainMenu();
85 cv.enterMainMenu();
86 }
87 }
88
89 public static void printMainMenu(){
90 System.out.println("\n-----------------客户信息管理软件-----------------");
91 System.out.println(" 1 添 加 客 户");
92 System.out.println(" 2 修 改 客 户");
93 System.out.println(" 3 删 除 客 户");
94 System.out.println(" 4 客 户 列 表");
95 System.out.println(" 5 退 出\n");
96 System.out.print(" 请选择(1-5):");
97 }
98 }