【计服15】实验三参考代码

以下代码仅供参考,请各位同学在仔细分析的基础之上,完善、扩展原代码。

/**
 * @(#)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;
           }      
       }

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值