日期:2014-05-20 浏览次数:20853 次
import java.util.Scanner; public class PhoneBook { private String[][] phones; public PhoneBook(){ phones = new String[100][5]; } public void command(int cmd){ switch(cmd){ case 1 : addInfo(); break; case 2 : search(); break; case 3 : deleteInfo(); break; default : break; } } public void addInfo(){ System.out.println("addInfo();"); //添加通讯录 //通讯录满的处理 } public void search(){ System.out.println("search();"); Scanner sc = new Scanner(System.in); System.out.println("请输入操作:\n 1 : byname\n 2 : byphonenum\n 3 : byphoneid"); int cmd = sc.nextInt(); switch(cmd){ case 1 : searchByName(); break; case 2 : searchByPhoneNum(); break; case 3 : searchByPhoneId(); break; default : break; } } public void searchByName(){ System.out.println("searchByName();"); //通讯录搜索byName } public void searchByPhoneNum(){ System.out.println("searchByPhoneNum();"); //通讯录搜索byPhoneNum } public void searchByPhoneId(){ System.out.println("searchByPhoneId();"); //通讯录搜索byPhoneId } public void deleteInfo(){ System.out.println("deleteInfo();"); //通讯录删除 //通讯录空的处理 } public static void main(String[] args){ PhoneBook pb = new PhoneBook(); Scanner sc = new Scanner(System.in); while(true){ System.out.println("请输入操作:\n 1 : addInfo\n 2 : search\n 3 : deleteInfo"); int cmd = sc.nextInt(); pb.command(cmd); } } }
------解决方案--------------------