您好,登錄后才能下訂單哦!
這篇文章主要介紹“java如何實(shí)現(xiàn)簡單的客戶信息管理系統(tǒng)”,在日常操作中,相信很多人在java如何實(shí)現(xiàn)簡單的客戶信息管理系統(tǒng)問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”java如何實(shí)現(xiàn)簡單的客戶信息管理系統(tǒng)”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
首先給大家看一下總的操作界面(別看簡單,里面的還是有東西的),后面就附上實(shí)現(xiàn)源碼、要求和注釋
Customer類
下面是關(guān)于Customer類的編寫要求:
* 用來封裝客戶的以下信息
* Sting name
* int age
* char gender
* Stirng phone
* String email
* 提供getset方法
* 構(gòu)造器自行設(shè)定
public class Customer { private String name; private int age; private String gender; private String phone; private String email; public Customer() { } public Customer(String name,int age,String gender,String phone,String email) { this.name = name; this.age = age; this.gender = gender; this.phone = phone; this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
CustomerList類
下面是關(guān)于CustomerList類的編寫要求:
* CustomerList類的設(shè)計(jì)
* Customer[] 用來保存客戶信息
* int total 用來保存當(dāng)前存入客戶數(shù)量
* 該類至少提供以下的構(gòu)造器和方法
* public CustomerLIst(int totalCustomer);
* public boolean addCustomer(Customer customer);
* public boolean replaceCustomer(int index,Customer cust);
* public boolean deleteCustomer(int index);
* public Customer[] getallCustomer();
* public Customer getCustomer(int index);
* public int getToal();
public class CustomerList { private static Customer customers[]; private static int total; public CustomerList(int totalCustomer) { customers = new Customer[totalCustomer]; } // 添加客戶 public boolean addCustomer(Customer customer) { if(total >= customers.length) { return false; } customers[total++] = customer; return true; } // 修改指定位置的客戶信息 public boolean replaceCustomer(int index,Customer cust) { if(index < 0 || index >= total) { return false; } customers[index] = cust; return true; } // 刪除指定位置的客戶 public boolean deleteCustomer(int index) { if(index < 0 || index >= total) { return false; } for(int i = index;i < total - 1;i++) { customers[i] = customers[i+1]; } customers[total - 1] = null; total--; return true; } // 得到所有客戶的信息 public static Customer[] getallCustomer() { Customer[] custs = new Customer[total]; for(int i = 0;i < total;i++) { custs[i] = customers[i]; } return custs; } // 得到指定客戶的信息 public Customer getCustomer(int index) { if(index < 0 || index >= total) { return null; } return customers[index]; } // 得到Customers中所有客戶的個(gè)數(shù) public static int getTotal() { return total; } }
CustomerView類
CustomerView類的編寫
* 主模塊:用于用戶界面的展示、與用戶交互
* CustomerList customerList = new CustomerList(10)
* 應(yīng)含有的構(gòu)造器和方法
* private void enterMainMenue()
* private void addNewCustomer()
* private void modifyCustomer()
* private void deleteCustomer()
* private void listAllCustomers()
* private static void main(String[] args)
public class CustomerView { CustomerList customerList = new CustomerList(10); public CustomerView() { Customer customer = new Customer("王龍", 20, "Male", "18965391649", "465989777@qq.com"); customerList.addCustomer(customer); } // 用戶主菜單 private void enterMainMenue() { System.out.println("-----------------客戶信息管理系統(tǒng) --------------------"); System.out.println(" 1-添加客戶"); System.out.println(" 2-修改客戶"); System.out.println(" 3-刪除客戶"); System.out.println(" 4-客戶列表"); System.out.println(" 5-退出"); System.out.println("請選擇1-5:"); } // 添加客戶 private void addNewCustomer() { // System.out.println("添加客戶的操作"); System.out.println("-----------------添加客戶-------------------------"); Scanner in = new Scanner(System.in); System.out.print("姓名:"); String name = in.nextLine(); System.out.print("年齡:"); int age = in.nextInt(); System.out.print("性別:"); String gender = in.nextLine(); System.out.print("電話:"); String phone = in.nextLine(); System.out.print("郵箱:"); String email = in.nextLine(); // 將上述數(shù)據(jù)封裝到Customer中 Customer customer = new Customer(name, age, gender, phone, email); boolean isSuccess = customerList.addCustomer(customer); if (isSuccess == true) { System.out.println("---------------添加完成---------------------"); } else { System.out.println("---------------客戶目錄已滿,添加失??!---------------------"); } } // 修改客戶 private void modifyCustomer() { // System.out.println("修改客戶的操作"); Scanner in = new Scanner(System.in); Customer cust; int num; System.out.print("請選擇待修改客戶的編號(hào)(-1退出):"); while (true) { num = in.nextInt(); if (num == -1) { return; } cust = customerList.getCustomer(num - 1); if (cust == null) { System.out.print("無法找到指定客戶,請選擇待修改客戶的編號(hào)(-1退出):"); } else { break; } } // 開始修改客戶信息 System.out.print("姓名(" + cust.getName() + "):"); String name = in.nextLine(); System.out.print("性別(" + cust.getGender() + "):"); String gender = in.nextLine(); System.out.print("年齡(" + cust.getAge() + "):"); int age = in.nextInt(); System.out.print("電話(" + cust.getPhone() + "):"); String phone = in.nextLine(); System.out.print("郵箱(" + cust.getEmail() + "):"); String email = in.nextLine(); Customer cust2 = new Customer(name, age, gender, phone, email); boolean isreplace = customerList.replaceCustomer(num - 1, cust2); if (isreplace == true) { System.out.println("---------------修改完成---------------------"); } else { System.out.println("---------------修改失敗---------------------"); } } // 刪除用戶 private void deleteCustomer() { // System.out.println("刪除客戶的操作"); Scanner in = new Scanner(System.in); int num; System.out.println("------------------刪除客戶-----------------------"); while (true) { System.out.println("輸入要?jiǎng)h除的客戶的序號(hào)(-1退出):"); num = in.nextInt(); if (num == -1) { return; } Customer customer = customerList.getCustomer(num - 1); if (customer == null) { System.out.println("------------------刪除失??!-----------------------"); return; } // 執(zhí)行刪除操作 System.out.print("是否確認(rèn)刪除(y/n):"); char isdelete = in.nextLine().charAt(0); if (isdelete == 'y') { boolean is = customerList.deleteCustomer(num - 1); if(is) { System.out.println("------------------刪除成功-----------------------"); }else { System.out.println("------------------刪除失敗-----------------------"); } }else { break; } } } // 列出所有客戶信息 private void listAllCustomers() { System.out.println("---------------客戶列表--------------------"); int total = CustomerList.getTotal(); if (total == 0) { System.out.println("沒有客戶記錄!"); } else { System.out.println("編號(hào)\t姓名\t性別\t電話\t\t郵箱\t"); Customer custs[] = CustomerList.getallCustomer(); for (int i = 0; i < custs.length; i++) { Customer cust = custs[i]; System.out.println((i + 1) + "\t" + cust.getName() + "\t" + cust.getGender() + "\t" + cust.getPhone() + "\t" + cust.getEmail()); } } System.out.println("---------------客戶列表加載完成--------------------"); } // 主函數(shù) public static void main(String[] args) { CustomerView view = new CustomerView(); Scanner in = new Scanner(System.in); boolean isFlag = true; while (isFlag) { view.enterMainMenue(); char menu = in.nextLine().charAt(0); switch (menu) { case '1': view.addNewCustomer(); break; case '2': view.modifyCustomer(); break; case '3': view.deleteCustomer(); break; case '4': view.listAllCustomers(); break; case '5': System.out.print("確認(rèn)是否退出(y/n):"); char flag = in.nextLine().charAt(0); if (flag == 'y') { isFlag = false; } break; } // isFlag = false; } in.close(); } }
到此,關(guān)于“java如何實(shí)現(xiàn)簡單的客戶信息管理系統(tǒng)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。