求java通讯录小程序 有增删改查就行 不需要连数据库
推荐于2018-04-10
展开全部
给你写了个,大的功能实现了,有些细节没处理,你自己改下就行了:public class Test2 { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
message(); } public static void message()
{
Map map = new HashMap();
int x = 0;
exit:
for(;;)
{
System.out.println("1、保存 2、查询3、删除 4、修改 5、退出");
Scanner scanner1 = new Scanner(System.in);
char []choose = scanner1.nextLine().toCharArray();
if(choose.length>1)
{
System.out.println("只能输入1-5的数字");
}else {
switch (choose[0]) {
case '1': System.out.print("请输入名字:");
Scanner scanner2 = new Scanner(System.in);
String name = scanner2.nextLine();
System.out.print("请输入电话号码:");
Scanner scanner3 = new Scanner(System.in);
String phone = scanner3.nextLine();
map.put(name,phone);
System.out.println("保存成功");
break;
case '2':
if(map.size()==0)
{
System.out.println("通讯录为空,请先添加");
}else {
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = (String) it.next();
String value = (String) map.get(key);
System.out.println(key+" "+value);
}
}
break;
case '3':
System.out.print("请输入要删除的名字:");
Scanner scanner4 = new Scanner(System.in);
String deletName = scanner4.nextLine();
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = (String) it.next();
if(deletName.equals(key))
{
map.remove(key);
System.out.println("删除成功");
} }
break;
case '4':
// map.remove()
System.out.print("请输入你要修改的通讯人的名字:");
Scanner scanner5 = new Scanner(System.in);
String updateName = scanner5.nextLine();
Iterator it1 = map.keySet().iterator();
while(it1.hasNext()){
String key = (String) it1.next();
if(updateName.equals(key))
{
map.remove(key);
}
}
System.out.print("请输入修改后的通讯人的名字:");
Scanner scanner6 = new Scanner(System.in);
String name1 = scanner6.nextLine();
System.out.print("请输入修改后的通讯人的电话号码:");
Scanner scanner7 = new Scanner(System.in);
String phone1 = scanner7.nextLine();
map.put(name1,phone1);
System.out.println("保存成功");
break;
case '5':
break exit;
default:
break;
}
}
}
}
}
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
message(); } public static void message()
{
Map map = new HashMap();
int x = 0;
exit:
for(;;)
{
System.out.println("1、保存 2、查询3、删除 4、修改 5、退出");
Scanner scanner1 = new Scanner(System.in);
char []choose = scanner1.nextLine().toCharArray();
if(choose.length>1)
{
System.out.println("只能输入1-5的数字");
}else {
switch (choose[0]) {
case '1': System.out.print("请输入名字:");
Scanner scanner2 = new Scanner(System.in);
String name = scanner2.nextLine();
System.out.print("请输入电话号码:");
Scanner scanner3 = new Scanner(System.in);
String phone = scanner3.nextLine();
map.put(name,phone);
System.out.println("保存成功");
break;
case '2':
if(map.size()==0)
{
System.out.println("通讯录为空,请先添加");
}else {
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = (String) it.next();
String value = (String) map.get(key);
System.out.println(key+" "+value);
}
}
break;
case '3':
System.out.print("请输入要删除的名字:");
Scanner scanner4 = new Scanner(System.in);
String deletName = scanner4.nextLine();
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = (String) it.next();
if(deletName.equals(key))
{
map.remove(key);
System.out.println("删除成功");
} }
break;
case '4':
// map.remove()
System.out.print("请输入你要修改的通讯人的名字:");
Scanner scanner5 = new Scanner(System.in);
String updateName = scanner5.nextLine();
Iterator it1 = map.keySet().iterator();
while(it1.hasNext()){
String key = (String) it1.next();
if(updateName.equals(key))
{
map.remove(key);
}
}
System.out.print("请输入修改后的通讯人的名字:");
Scanner scanner6 = new Scanner(System.in);
String name1 = scanner6.nextLine();
System.out.print("请输入修改后的通讯人的电话号码:");
Scanner scanner7 = new Scanner(System.in);
String phone1 = scanner7.nextLine();
map.put(name1,phone1);
System.out.println("保存成功");
break;
case '5':
break exit;
default:
break;
}
}
}
}
}
2013-09-25
展开全部
前几天就写了一个班级通讯录系统、、、采用Struts2+Hibernate+Ajax实现的、、连接的是Mysql数据库。还包了头像上传什么xx的~~~java web项目来的!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |