Java通讯录系统 简单实现Java通讯录系统
小李佳 人气:0想了解简单实现Java通讯录系统的相关内容吗,小李佳在本文为您仔细讲解Java通讯录系统的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:java,通讯录,下面大家一起来学习吧。
import java.util.Scanner; class Person { String name; String number; } class connect { Person a[]; int number; public connect() { a=new Person[100]; number=0; } public String add(String name,String number) { if(number == "0") System.out.println("请先添加联系人!"); if(this.number>99) return "添加失败"; a[this.number]=new Person(); a[this.number].name=name; a[this.number].number=number; this.number++; return "添加成功"; } public Person seek(String name) { if(number == 0) System.out.println("请先添加联系人!"); for(int i=0;i<number;i++) { if((a[i].name).equals(name)) { System.out.println("联系人: "+a[i].name+" 电话:"+a[i].number); return a[i]; } } return null; } public void look() { if(number == 0) System.out.println("请先添加联系人!"); for(int i=0;i<number;i++) { System.out.println("联系人 "+a[i].name+" 电话 "+a[i].number); } } public String delete(String name) { if(number == 0) System.out.println("请先添加联系人:"); for(int i=0;i<number;i++) { if((a[i].name).equals(name)) { a[i]=a[this.number-1]; number=number-1; return "删除成功"; } } return "删除失败"; } } public class text1 { public static void main(String[]args) { Scanner sc=new Scanner(System.in); Scanner input = new Scanner(System.in); System.out.println("\t\t\t欢迎使用通讯录系统\n"); System.out.println("\t\t\t1.创建用户\n\n\t\t\t2.退出\n"); System.out.println("____________________________________________________________________\n\n"); System.out.print("请选择相应选项:"); int num2 = sc.nextInt(); while(num2!=2) { switch (num2) { case 1: { connect c = new connect(); System.out.println("\t\t\t1.浏览\n");System.out.println("\t\t\t2.查找\n"); System.out.println("\t\t\t3.添加\n");System.out.println("\t\t\t4.删除\n"); System.out.println("\t\t\t5.退出\n");System.out.println("请选择相应选项:"); System.out.println("输入指令:"); int num1 = input.nextInt(); switch (num1) { case 1:c.look();break; case 2: { System.out.println("输入查找的名字:"); String n1 = sc.next();c.seek(n1); }break; case 3: { System.out.println("输入要添加的人数:"); System.out.println("enter:"); int s=sc.nextInt(); for(int i=0;i<s;i++) { System.out.println("请输入第"+(i+1)+"个人的名字:"); String name=sc.next(); String number=sc.next(); c.add(name,number); } }break; case 4: { System.out.println("输入删除的姓名:"); String n3 = sc.next();c.delete(n3); }break; default: { System.out.println("\t\t\t谢谢您的使用\n"); System.exit(0); } } }break; case 2:System.out.println("\t\t\t谢谢您的使用\n");break; default:System.out.println("输入有误!");num2=2; } } } }
加载全部内容