Created
April 7, 2013 13:58
-
-
Save KingSirLee/5330599 to your computer and use it in GitHub Desktop.
简单的联系人的查找和存储。。。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Content { | |
private String name; | |
private String tel; | |
private String email; | |
private String QQ; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getTel() { | |
return tel; | |
} | |
public void setTel(String tel) { | |
this.tel = tel; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
public String getQQ() { | |
return QQ; | |
} | |
public void setQQ(String qQ) { | |
QQ = qQ; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mobile { | |
Content []cont=new Content[100]; | |
java.util.Scanner input=new java.util.Scanner(System.in); | |
public void start(){ | |
System.out.println("******************"); | |
System.out.println("请选择要进行的操作:"); | |
System.out.println("1.查询姓名"); | |
System.out.println("2.保存姓名"); | |
System.out.println("退出 quit"); | |
System.out.println("******************"); | |
String index=input.next(); | |
if(index.equals("quit")){ | |
System.out.println("退出成功!"); | |
}else{ | |
if(index.equals("1")){ | |
findName(); | |
}else if(index.equals("2")){ | |
saveName(); | |
}else{ | |
System.out.println("操作有误,请重新选择!"); | |
start(); | |
} | |
} | |
} | |
private void saveName() { | |
System.out.println("请输入姓名:"); | |
String name=input.next(); | |
System.out.println("请输入电话:"); | |
String tel=input.next(); | |
System.out.println("请输入Email:"); | |
String email=input.next(); | |
System.out.println("请输入QQ号码:"); | |
String QQ=input.next(); | |
Content c=new Content(); | |
c.setName(name); | |
c.setTel(tel); | |
c.setEmail(email); | |
c.setQQ(QQ); | |
boolean flag=false; | |
for(int i=0;i<cont.length;i++){ | |
if(cont[i]==null){ | |
cont[i]=c; | |
flag=true; | |
break; | |
} | |
} | |
if(flag){ | |
System.out.println("保存成功!"); | |
}else{ | |
System.out.println("内存已满。保存失败!"); | |
} | |
start(); | |
} | |
private void findName() { | |
System.out.println("请输入名字:"); | |
String name=input.next(); | |
Content c=null; | |
for(int i=0;i<cont.length;i++){ | |
if(cont[i]!=null&&name.equals(cont[i].getName())){ | |
c=cont[i]; | |
break; | |
} | |
} | |
if(c==null){ | |
System.out.println("您查找的用户不存在!"); | |
}else{ | |
System.out.println("******************"); | |
System.out.println(c.getName()); | |
System.out.println("电话:"+c.getTel()); | |
System.out.println("Email:"+c.getEmail()); | |
System.out.println("QQ:"+c.getQQ()); | |
} | |
start(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestMobile { | |
public static void main(String[] args) { | |
Mobile m=new Mobile(); | |
m.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment