package 课设;
import java.util.Scanner;
class Person
{
String name;
int number;
}
class connect
{
Person a[];
public static int number;
public connect()
{
a=new Person[100];
connect.number=0;
}
public String add(String name,int number)
{
if(connect.number == 0)
System.out.println("请先添加联系人!");
if(connect.number>99)
return "添加失败";
a[connect.number]=new Person();
a[connect.number].name=name;
a[connect.number].number=number;
connect.number++;
return "添加成功";
}
public Person seek(String name)
{
if(connect.number == 0)
System.out.println("请先添加联系人!");
for(int i=0;i<connect.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(connect.number == 0)
System.out.println("请先添加联系人!");
for(int i=0;i<connect.number;i++)
{
System.out.println("联系人 "+a[i].name+" 电话 "+a[i].number);
}
}
public String delete(String name)
{
if(connect.number == 0)
System.out.println("请先添加联系人:");
for(int i=0;i<connect.number;i++)
{
if((a[i].name).equals(name))
{
a[i]=a[connect.number-1];
connect.number=connect.number-1;
return "删除成功";
}
}
return "删除失败";
}
}
public class 通讯录
{
public static void main(String[]args)
{
int num3=2;
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();
do {
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("输入指令:");
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("输入要添加的人数:");
int s=sc.nextInt();
connect.number=s;
for(int i=0;i<s;i++)
{
System.out.println("请输入第"+(i+1)+"个人的个人信息:");
String name=sc.next();
int number=sc.nextInt();
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;
}
System.out.println("如果继续使用输入1,退出请输入2");
Scanner pd=new Scanner(System.in);
num3 = pd.nextInt();
}while(num3==1);
System.out.println("谢谢使用!");
}
}