java企业员工管理系统,基于java的信息管理系统
本文实例为大家分享了爪哇岛实现简单客户信息管理系统的具体代码,供大家参考,具体内容如下
全篇文章开源,源码供读者使用。这是一篇关于爪哇岛的客户信息管理系统的文章,里面简单实现了数据库管理系统的基本功能,可以算是算笔者的学习笔记,也为大家学习提供便利。所以代码都是在一个包下完成的,所以没有使用导包的操作,省去了外卖项目的申明,剩下的就写的文章里了。话不多说,看文章吧。首先给大家看一下总的操作界面(别看简单,里面的还是有东西的),后面就附上实现源码、要求和注释
Customer类
下面是关于顾客类的编写要求:
* 用来封装客户的以下信息*昵称*年龄*性别*电话号码*电子邮件*提供装置方法* 构造器自行设定
公共类客户{私有字符串名称;私人年龄;私串性别;私弦电话;私人字符串电子邮件;public Customer(){ } public Customer(字符串名称,int age,字符串性别,字符串电话,字符串电子邮件){ this。name=名称;this.age=年龄;this.gender=性别;this . phone=phone this . email=email } public String getName(){ return name;} public void set name(String name){ this。name=名称;} public int getAge(){ return age;} public void setAge(int age){ this。年龄=年龄;} public String get gender(){ return gender;} public void set gender(字符串性别){ this。性别=性别;} public String get phone(){ return phone;}公共void set phone(String phone){ this。电话=电话;}公共字符串getEmail() {返回邮件;} public void set email(String email){ this。email=email} }CustomerList类
下面是关于客户列表类的编写要求:
*客户列表类的设计*客户[]用来保存客户信息*利息总计用来保存当前存入客户数量* 该类至少提供以下的构造器和方法*公共客户列表(int total customer);* public boolean addCustomer(客户客户);* public boolean替换Customer(int index,Customer cust);*公共布尔删除客户(int索引);*公共客户[]getall customer();*公共客户获取客户(int index);* public int get toal();
公众的类客户列表{私有静态客户客户[];私有静态int totalpublic客户列表(int total Customer){ customers=新客户[客户总数];} //添加客户公众的布尔值添加客户(客户客户){ if(t
otal >= 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中所有客户的个数 public static int getTotal() { return total; } }CustomerView类
CustomerView类的编写
* 主模块:用于用户界面的展示、与用户交互* CustomerList customerList = new CustomerList(10)* 应含有的构造器和方法* 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("-----------------客户信息管理系统 --------------------"); 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(); // 将上述数据封装到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("请选择待修改客户的编号(-1退出):"); while (true) { num = in.nextInt(); if (num == -1) { return; } cust = customerList.getCustomer(num - 1); if (cust == null) { System.out.print("无法找到指定客户,请选择待修改客户的编号(-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("输入要删除的客户的序号(-1退出):"); num = in.nextInt(); if (num == -1) { return; } Customer customer = customerList.getCustomer(num - 1); if (customer == null) { System.out.println("------------------刪除失败!-----------------------"); return; } // 执行删除操作 System.out.print("是否确认删除(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("编号t姓名t性别t电话tt邮箱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("---------------客户列表加载完成--------------------"); } // 主函数 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("确认是否退出(y/n):"); char flag = in.nextLine().charAt(0); if (flag == y) { isFlag = false; } break; } // isFlag = false; } in.close(); }}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持盛行IT。
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。