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

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Java Interface, Abstract Class, and Event-Driven Animations
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Inheritance and Polymorphism.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Chapter 10: Inheritance and Polymorphism
Chapter 10 Classes Continued
Chapter 11: Inheritance and Polymorphism Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Inheritance using Java
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
C# G 1 CSC 298 Object Oriented Programming Part 2.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Clicker questions 10/24/13 CSE 1102 Fall θ (x,y) (0,0) What is the relationship between θ and (x,y) ? A.y = mx + b B.θ = x 2 + y 2 C.tan(θ) = x/y;
Chapter 5 Introduction to Defining Classes
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
© 2006 Pearson EducationDesign Patterns1 of 20 A Final Example: A Traffic Light Let’s model a traffic light! – here’s the spec: Have a column of two circles.
Clicker quick questions 10/17/13 CSE 1102 Fall 2013.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
Interfaces and Inner Classes
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Clicker quiz 11/5/13 CSE 1102 Fall A. a FlowLayout B. a BorderLayout C. a GridGrouping D. a JSplitPane E. a GridLayout Suppose we want to to lay.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Clicker quiz 10/29/13 CSE 1102 Fall __________ is visible to code in the inner class (at ????, say): A.All protected methods and protected instance.
1 DemoBasic_v3, DemoBasic_v4 JButton JLabel. 2 Registering an ActionListener Register by invoking the following from within constructor DemoBasicFrame.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object-Oriented Design
Abstract classes and interfaces
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
“Form Ever Follows Function” Louis Henri Sullivan
Inheritance and Polymorphism
Chapter 11: Inheritance and Polymorphism
Intro To Classes Review
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Chapter 9 Inheritance and Polymorphism
Abstract classes and interfaces
Java Programming Language
slides created by Ethan Apter
Week 6 Object-Oriented Programming (2): Polymorphism
CSE 8A Lecture 6 Reading for next class:
Advanced Java Programming
slides created by Ethan Apter
OO Design with Inheritance
CIS 199 Final Review.
Abstract classes and interfaces
Review of Previous Lesson
Presentation transcript:

Clicker quiz 10/22/13 CSE 1102 Fall 2013

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

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

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]

Clicker questions 10/22/13 CSE 1102 Fall 2013

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]

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.

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

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.

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.

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]

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

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

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

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)

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

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.

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.