重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍了java如何实现电话本管理系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
创新互联是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括做网站、网站制作、电商网站制作开发、微信小程序定制开发、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!
用JAVA实现一个简单的电话本管理系统,能存储100个人的姓名、性别、年龄、电话等信息,并能对此系统进行增删改查的操作。
部分代码如下:
public class Phbook { public static void main(String[] args) { Person personarray[] = new Person[100]; int index = 0; for (int i = 0; i < 100; i++) { System.out.println("电话本管理系统"); System.out.println("1.添加 2.删除 3.修改 4.查询所有 5.根据姓名查询 0.退出"); System.out.println("请选择业务"); Scanner input = new Scanner(System.in); int a = input.nextInt(); switch (a) { case 0: { System.out.println("退出系统"); i = 101; } ; break; case 1: { System.out.println("添加电话本"); System.out.print("姓名:"); Scanner n = new Scanner(System.in); String name = n.next(); System.out.print("性别:"); Scanner s = new Scanner(System.in); String sex = s.next(); System.out.print("年龄:"); Scanner ag = new Scanner(System.in); String age = ag.next(); System.out.print("电话:"); Scanner tel = new Scanner(System.in); String telnum = tel.next(); System.out.print("qq:"); Scanner q = new Scanner(System.in); String qq = q.next(); System.out.print("地址:"); Scanner add = new Scanner(System.in); String address = add.next(); personarray[index] = new Person(name, sex, age, telnum, qq, address); index = index + 1; } ; break; case 2: { System.out.println("删除电话本"); System.out.println("需要删除的姓名:"); Scanner name0 = new Scanner(System.in); String namedel = name0.next(); for (int j = 0; j < index; j++) { if (namedel.equals(personarray[j].name) == true) { for (int n = j; n < index - 1; n++) { personarray[n] = personarray[n + 1]; } index = index - 1; break; } if (j == index - 1) { System.out.println("查无此人"); } } } ; break; case 3: { System.out.println("修改电话本"); System.out.println("需要修改的姓名:"); Scanner name00 = new Scanner(System.in); String nameedit = name00.next(); for (int k = 0; k < index; k++) { if (nameedit.equals(personarray[k].name) == true) { System.out.print("姓名:"); Scanner xm1 = new Scanner(System.in); String name1 = xm1.next(); System.out.print("性别:"); Scanner xb1 = new Scanner(System.in); String sex1 = xb1.next(); System.out.print("年龄:"); Scanner nl1 = new Scanner(System.in); String age1 = nl1.next(); System.out.print("电话:"); Scanner dh2 = new Scanner(System.in); String telnum1 = dh2.next(); System.out.print("qq:"); Scanner q1 = new Scanner(System.in); String qq1 = q1.next(); System.out.print("地址:"); Scanner dz1 = new Scanner(System.in); String address1 = dz1.next(); personarray[k] = new Person(name1, sex1, age1, telnum1, qq1, address1); break; } if (k == index - 1) { System.out.println("查无此人"); } } } ; break; case 4: { System.out.println("显示所有电话本"); for (int l = 0; l < index; l++) { System.out.println(personarray[l].toString()); } } ; break; case 5: { System.out.println("查询电话本"); System.out.println("需要查询的姓名:"); Scanner na = new Scanner(System.in); String nameprint = na.next(); for (int m = 0; m < index; m++) { if (nameprint.equals(personarray[m].name) == true) { System.out.println(personarray[m].toString()); break; } if (m == index - 1) { System.out.println("查无此人"); } } } ; break; default: { System.out.println("无此功能"); } ; break; } } public Person(String name, String sex, String age, String telnum, String qq, String address) { this.name = name; this.sex = sex; this.age = age; this.telnum = telnum; this.qq = qq; this.address = address; } public String toString() { return " [姓名=" + name + ", 性别=" + sex + ", 年龄=" + age + ", 电话=" + telnum + ",qq=" + qq + ", 地址=" + address + "]"; }
下面是程序运行的结果:
感谢你能够认真阅读完这篇文章,希望小编分享的“java如何实现电话本管理系统”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!