简单实现Java通讯录系统

网友投稿 265 2023-02-17


简单实现Java通讯录系统

本文实例为大家分享了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.numbeMDlvhr]=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

{

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

{

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

{

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[]aMDlvhrgs)

{

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

{

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;

}

}

}

}

{

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

{

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

{

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[]aMDlvhrgs)

{

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

{

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;

}

}

}

}

{

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

{

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[]aMDlvhrgs)

{

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

{

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;

}

}

}

}

{

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[]aMDlvhrgs)

{

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

{

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;

}

}

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot手动使用EhCache的方法示例
下一篇:接口测试的数据验证(接口测试验证码处理)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~