以下代码仅供参考,请各位同学在仔细分析的基础之上,完善、扩展原代码。
/**
* @(#)CommEntryTest.java
*
* CommEntryTest application
*
* @author
* @version 1.00 2016/4/5
*/
import java.io.*;
import java.util.*;
class CommEntry{
String name;
String tel;
public void input(){
Scanner scan = new Scanner(System.in);
System.out.println("Input name");
name = scan.nextLine();
System.out.println("Input tel");
tel = scan.nextLine();
}
public void output(){
System.out.println("name:" + name);
System.out.println("tel:" + tel);
}
public void setName(String nm){
name = nm;
}
public String getName(){
return name;
}
public void setTel(String t){
tel = t;
}
public String getTel(){
return tel;
}
}
public class CommEntryTest {
public int displayMenu()throws IOException{
Scanner scan = new Scanner(System.in);
int iChoice;
System.out.println();
System.out.println("================");
System.out.println("1.输入通讯录条目");
System.out.println("2.输出通讯录条目");
System.out.println("3.修改姓名");
System.out.println("4.修改电话");
System.out.println("0.退出");
System.out.println("================");
System.out.println("请选择(0-4):");
iChoice = scan.nextInt();
return iChoice;
}
public static void main(String[] args)throws IOException {
CommEntry ce;
ce = new CommEntry();
CommEntryTest test;
test = new CommEntryTest();
Scanner scan = new Scanner(System.in);
int iChoice =1;
while (iChoice!=0){
iChoice = test.displayMenu();
switch (iChoice){
case 1:
ce.input();
break;
case 2:
ce.output();
break;
case 3:{
String nm;
nm = scan.nextLine();
ce.setName(nm);
break;
}
case 4:{
String t;
t = scan.nextLine();
ce.setTel(t);
break;
}
case 0:
break;
}
}
}
}