1.1 面向对象学习暂告一段落,请使用思惟导图,以封装、继承、多态为核心概念画一张思惟导图,对面向对象思想进行一个总结。
java
Q1.clone方法
1.1 Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时须要注意什么?编程
1.2 本身设计类时,通常对什么样的方法使用protected进行修饰?以做业Shape为例说明。 app
1.3 在test1包中编写简单的Employee类,在test2包中新建一个TestProtected类,并在main中尝试调用test1包中的Employee的clone方法克隆一个新对象,可否成功?为何? eclipse
Q2.使用匿名类与Lambda表达式改写题集面向对象2-进阶-多态接口内部类的题目5-2仅需粘贴关键代码与运行结果,图片不要太大。ide
Arrays.sort(str, new Comparator<PersonSortable2>(){ public int compare(PersonSortable2 o1, PersonSortable2 o2) { return o1.getName().compareTo(o2.getName()); } }); Arrays.sort(str, new Comparator<PersonSortable2>(){ public int compare(PersonSortable2 o1, PersonSortable2 o2) { return Integer.toString(o1.getAge()).compareTo(Integer.toString(o2.getAge())); } });
Arrays.sort(str, (PersonSortable2 o1, PersonSortable2 o2) ->(o1.getName().compareTo(o2.getName()))); Arrays.sort(str, (PersonSortable2 o1, PersonSortable2 o2) -> (o1.getAge()-o2.getAge()));
Q3.分析下列代码,回答shapeComparator所指向的对象与Comparator接口有什么关系?函数
Comparator<Shape> shapeComparator = new Comparator<Shape>() { @Override public int compare(Shape o1, Shape o2) { //你的代码 } };
Q4.GUI中的事件处理
4.1 写出事件处理模型中最重要的几个关键词。学习
4.2 使用代码与注释,证实你理解了事件处理模型。设计
public class MainGUI { public static void main(String[] args) { JFrame f = new JFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton b = new JButton("Press Me!");//事件是点击按钮,事件源是按钮 b.addActionListener(new ButtonHandler());//注册监听器,为了可以让事件监听器检查到某个组件(事件源(此处是按钮))是否发生了某些事件,而且在发生事件时激活时间处理器进行相应的处理,必须注册监听器。 f.add(b); f.setSize(200, 100); f.setVisible(true); } private static class ButtonHandler implements ActionListener{//监听器,不一样类型的事件须要有不一样的监听器,监听器必须实现监听器接口,而后进行事件处理“Action occurred” public void actionPerformed(ActionEvent e) { System.out.println("Action occurred"); System.out.println(e.getSource());//得到事件源 } } }
Q5.结对编程:面向对象设计(大做业2-很是重要,未完成-2)继续完善上周的项目做业。考核点以下:
5.1 尝试使用图形界面改写。code
private void clothesComboBoxActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(0==(clothesComboBox.getSelectedIndex())){ jLabel.setText(clothes1.getName()); ... } if(1==(clothesComboBox.getSelectedIndex())){ jLabel.setText(clothes2.getName()); ... } ... } private void sumButtonActionPerformed(java.awt.event.ActionEvent evt) { count=Integer.parseInt(jTextField1.getText()); jTextArea1.setEditable(false); if(0==(clothesComboBox.getSelectedIndex())){ sum+=clothes1.getPrice()*count; jTextArea1.append("商品名:"+clothes1.getName()+"价格:"+clothes1.getPrice()+"购件数:"+count+"\n"); } if(1==(clothesComboBox.getSelectedIndex())){ ... } ... }
5.2 给出两人在码云上同一项目的提交记录截图。
orm
5.3 与上周相比,项目的主要改动是什么?