这篇文章主要介绍了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如何实现电话本管理系统”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。