您好,登錄后才能下訂單哦!
這篇文章主要介紹了java如何實(shí)現(xiàn)電話本管理系統(tǒng),具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
用JAVA實(shí)現(xiàn)一個(gè)簡(jiǎn)單的電話本管理系統(tǒng),能存儲(chǔ)100個(gè)人的姓名、性別、年齡、電話等信息,并能對(duì)此系統(tǒng)進(jìn)行增刪改查的操作。
部分代碼如下:
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("電話本管理系統(tǒng)"); System.out.println("1.添加 2.刪除 3.修改 4.查詢所有 5.根據(jù)姓名查詢 0.退出"); System.out.println("請(qǐng)選擇業(yè)務(wù)"); Scanner input = new Scanner(System.in); int a = input.nextInt(); switch (a) { case 0: { System.out.println("退出系統(tǒng)"); 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("需要?jiǎng)h除的姓名:"); 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("查無(wú)此人"); } } } ; 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("查無(wú)此人"); } } } ; 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("查無(wú)此人"); } } } ; break; default: { System.out.println("無(wú)此功能"); } ; 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 + "]"; }
下面是程序運(yùn)行的結(jié)果:
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“java如何實(shí)現(xiàn)電話本管理系統(tǒng)”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。