Java通讯录编程Word格式.docx
- 文档编号:21145527
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:12
- 大小:16.70KB
Java通讯录编程Word格式.docx
《Java通讯录编程Word格式.docx》由会员分享,可在线阅读,更多相关《Java通讯录编程Word格式.docx(12页珍藏版)》请在冰豆网上搜索。
publicclassMailList
privateFriend[]list=newFriend[50];
publicMailList()
{}
//显示菜单
publicvoidAddressbook()
/*System.out.println("
+--------------------------------------+"
);
System.out.println("
+请根据菜单选择您的操作:
+"
+按1:
显示全部好友+"
+按2:
添加好友+"
+按3:
查找好友+"
+按4:
修改好友+"
+按5:
删除好友+"
+按6:
显示菜单+"
+按0:
退出程序+"
+作者:
*/
BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));
请输入指令:
"
Strings;
intinstructions=-1;
try
{
s=buf.readLine();
instructions=Integer.parseInt(s);
}
catch(IOExceptione)
e.printStackTrace();
if(instructions>
6||instructions<
0)
System.out.println("
输入错误!
请根据菜单指令重新输入!
this.Addressbook();
if(instructions>
=0&
&
instructions<
=6)
switch(instructions)
{
case1:
//显示全部好友
intcount=0;
for(inti=0;
i<
list.length;
i++)
{
if(list[i]!
=null)
{
System.out.println(list[i].getName());
System.out.println(list[i].getTel());
count++;
}
}
System.out.println("
通讯录共有好友"
+count+"
人"
\n"
+"
this.Addressbook();
case2:
//添加好友信息
intindex=-1;
if(list[i]==null)
index=i;
break;
if(index==-1)
System.out.println("
通讯录已满,不能再添加好友!
return;
请输入好友信息"
姓名:
try
Stringname=buf.readLine();
电话:
Stringtel=buf.readLine();
list[index]=newFriend(name,tel);
添加成功!
catch(IOExceptione)
e.printStackTrace();
case3:
//查找好友
请输入要查找的好友姓名:
intm=0;
for(inti=0;
if(list[i]!
{
if(list[i].getName().equals(name))
{
System.out.println("
+list[i].getName());
+list[i].getTel());
m++;
}
}
if(m==0)
System.out.println("
查无此人!
}
case4:
//修改好友
请输入好友姓名:
try
for(inti=0;
是否要修改好友信息?
(y/n)"
Stringyn=buf.readLine();
if(yn.equals("
y"
))
{
System.out.println("
请选择要修改的信息.(name/tel)"
Stringnt=buf.readLine();
if(nt.equals("
name"
{
System.out.println("
请输入修改后的姓名。
Stringn=buf.readLine();
list[i].setName(n);
姓名修改成功!
修改后的信息:
是否要修改电话?
shi/fou"
Stringsf=buf.readLine();
if(sf.equals("
shi"
{
System.out.println("
请输入修改后的电话:
Stringt=buf.readLine();
list[i].setTel(t);
电话修改成功!
break;
}
elseif(sf.equals("
fou"
取消修改!
已退出该操作!
现在的信息如下:
else
已推出该操作!
}
elseif(nt.equals("
tel"
Stringt=buf.readLine();
list[i].setTel(t);
break;
else
}
elseif(yn.equals("
n"
{
break;
else
else
System.out.println("
break;
case5:
//删除好友
请输入要删除的好友姓名:
是否要删除该好友?
);
list[i]=null;
成功删除!
elseif(yn.equals("
取消删除!
查无此人!
//查找菜单
case6:
this.Addressbook();
case0:
System.exit(0);
//System.exit(0);
0--正常结束程序
//System.exit
(1);
1--异常关闭程序
}
过程三:
publicclassTest
publicstaticvoidmain(String[]args)
MailListm=newMailList();
m.Addressbook();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 通讯录 编程