您好,登錄后才能下訂單哦!
這篇文章主要介紹了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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。