用Java语言:
使用3个队列,分别保留手机上最近10个,未接来电、已接来电、已拨电话
2条回答 默认 最新
- 钰娘娘 2021-11-08 16:16关注
public class Main { public static void main(String[] args) { Main main = new Main(); Op op = new Op(); Scanner sc = new Scanner(System.in); int type; while((type=sc.nextInt())!=Op.OP_FINISH){ String mobile = ""; if (type < 4) { mobile = sc.next(); } op.operator(type,mobile); } } static class Op{ Memory tel; Memory notAccept; Memory accept ; public static final int OP_TEL = 1; public static final int OP_REFUSE = 2; public static final int OP_ACCEPT = 3; public static final int OP_TEL_PRINT = 4; public static final int OP_REFUSE_PRINT = 5; public static final int OP_ACCEPT_PRINT = 6; public static final int OP_FINISH = 7; public Op(){ tel = new Memory(); notAccept = new Memory(); accept = new Memory(); } public void operator(int type,String mobile){ switch (type){ case OP_TEL: addTel(mobile); break; case OP_REFUSE: addNotAccept(mobile); break; case OP_ACCEPT: addAccept(mobile); break; case OP_TEL_PRINT: System.out.println(getTelList()); break; case OP_REFUSE_PRINT: System.out.println(getNotAcceptList()); break; case OP_ACCEPT_PRINT: System.out.println(getAcceptList()); break; } } public void addTel(String mobile){ tel.add(mobile); } public Queue<String> getTelList(){ return tel.getList(); } public void addNotAccept(String mobile){ notAccept.add(mobile); } public Queue<String> getNotAcceptList(){ return notAccept.getList(); } public void addAccept(String mobile){ accept.add(mobile); } public Queue<String> getAcceptList(){ return accept.getList(); } } static class Memory{ Queue<String> list = null;//拨出 public Memory(){ list = new LinkedList<>(); } public void add(String mobile){ list.offer(mobile); if(list.size()>10) list.poll(); } public Queue<String> getList(){ return list; } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报