Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clicker quiz 10/22/13 CSE 1102 Fall 2013.

Similar presentations


Presentation on theme: "Clicker quiz 10/22/13 CSE 1102 Fall 2013."— Presentation transcript:

1 Clicker quiz 10/22/13 CSE 1102 Fall 2013

2 To write code that deals with events, the authors suggest you need a source, a listener that registers with the source, and a responder who responds to the event. Given this model, once things are initialized The source necessarily knows about the listener [CORRECT] the responder Both of these Neither of these

3 To write code that deals with events, the authors suggest you need a source, a listener that registers with the source, and a responder who responds to the event. Given this model, once things are initialized The listener necessarily knows about the source the responder [CORRECT] Both of these Neither of these

4 To write code that deals with events, the authors suggest you need a source, a listener that registers with the source, and a responder who responds to the event. Given this model, once things are initialized The responder necessarily knows about the source the listener Both of these Neither of these [CORRECT]

5 Clicker questions 10/22/13 CSE 1102 Fall 2013

6 In the source-listener-responder model discussed in the text (and implemented in Java), a listener can be associated with _______ source(s) and ________ responder(s) Fill in the blanks to make the above true one or zero, one or zero exactly one, exactly one one or zero, any number of any number of, one or zero any number of, any number of [CORRECT]

7 Excerpt from Bouncing Ball:
public class BouncingBall extends SmartEllipse implements Mover{ ... private final int MOVE_LEN = 5; public BouncingBall (java.awt.Color aColor, The assignment is outside of any method. This works because: It is the job of the constructor to initialize the instance variables. Variables whose names are in all capitals are constants. Variables that are described as final are set before the program executes. int is a built-in type, so it does not have to be instantiated. [CORRECT?] Any of the above is sufficient.

8 Modified Excerpt from Bouncing Ball:
if (nextX <= this.getMinBoundX{... else if (nextX >= this.getMaxBoundX{... else if (nextY <= this.getMinBoundY{... else if (nextY >= this.getMaxBoundY{... What difference does the red else make? No difference, unless the ball hits a corner. [CORRECT] No difference. No difference that anyone would ever notice. No difference, unless nextX and nextY are relative primes. None of the above is true

9 Modified Excerpt from Bouncing Ball:
if (nextX <= this.getMinBoundX{... else if (nextX >= this.getMaxBoundX{... else if (nextY <= this.getMinBoundY{... else if (nextY >= this.getMaxBoundY{... What is the most effective way to avoid making bugs like this? Plan on performing a lot of tests. Think about what the code is supposed to do, at a higher level than code. Program in a team, and document someone else’s code and read what the other person said about yours. Think carefully about test cases, being systematic about testing all combinations of values for conditionals. [CORRECT] All are equally effective.

10 Excerpt from Bouncing Ball:
if (nextX <= this.getMinBoundX{... else if (nextX >= this.getMaxBoundX{... if (nextY <= this.getMinBoundY{... else if (nextY >= this.getMaxBoundY{... Which is the most important reason for checking for less than the min, greater than the max? It’s cheap and safe. It’s checking the complement of the interior. It’s good policy to have self-healing code. There is nothing else stopping the Ball from going outside the boundaries. [CORRECT] All are equally important.

11 Excerpt from Bouncing Ball:
public int getMinBoundX(){ return (int) _panel.getX();} public int getMinBoundY(){ return (int) _panel.getY();} Which is the best reason for making methods, when the amount of code without the method would be the same? MinBound is a higher level idea than _panel.getX(). It’s easier to make mistakes using _panel.getX() than MinBoundX. It makes the code read more like documentation. The count of lines of code looks better. All are equally good reasons. [CORRECT]

12 Suppose I define an inner class, as was done in MoveTimer
Suppose I define an inner class, as was done in MoveTimer. The code in the inner class can access: public class Outer extends SomeClass implements SomeInterface{ ... private class Inner extends AnotherClass { ???? } __________ is visible to code in the inner class (at ????, say): All protected methods and protected instance variables of the outer class All public methods and public instance variables of the outer class All methods and all public instance variables of the outer class All methods and instance variables of the outer class. [CORRECT] None of the above is true

13 Consider MoveTimer: public class MoveTimer extends javax.swing.Timer{ private Mover _mover; public MoveTimer(int anInterval, Mover aMover){ super(anInterval, null); _mover = aMover; this.addActionListener(new MoveListener()); } private class MoveListener implements ActionListener { public void actionPerformed(ActionEvent e) { _mover.move(); This code illustrates which point about inner classes Inner classes have no constructors Instance variables of the outer class are visible to instances of the inner class [CORRECT] super can be called with null as a parameter An inner class is the subclass of its outer class. None of the above is true

14 Random behavior : import java.util.* ; Random _r ; _r = new Random() ; if(_r.nextDouble()>.5) { do something } else do something else

15 About repaint Both Component and JComponent have repaint methods.
Component has public void repaint() public void repaint(long millisecondsDelay) public void repaint(int x, int y, int width, int height) public void repaint(long millisecondsDelay, int x, int y, int width, int height)

16 More about repaint JComponent has public void repaint(Rectangle r)
public void repaint(long timeWithin, int x, int y, int width, int height)

17 About repaint: This code invokes which repaint method?
public class FishPanel extends javax.swing.JPanel{ public FishPanel(){ } private void move() { this.repaint(); This code invokes which repaint method? The one in JComponent, because it extends JPanel. The one in JComponent, because the keyword “this” is used. The one in Component, because that is the highest in the inheritance hierarchy. The one in Component, because there are no arguments. [CORRECT] Both, because the one in JComponent invokes the one in Component.

18 More about repaint: public class FishPanel extends javax.swing.JPanel{ public FishPanel(){ } private void move() { this.repaint(); If the paintComponent method is misspelled, what happens? Repaint works according to its specification. There is a runtime error message about a Null Pointer for the method. There is a compile time error message about not implementing a method for JPanel. The display looks fine until it is resized, or changes from covered to uncovered. [CORRECT] None of the above.


Download ppt "Clicker quiz 10/22/13 CSE 1102 Fall 2013."

Similar presentations


Ads by Google