Download presentation
Presentation is loading. Please wait.
Published byAda Dennis Modified over 9 years ago
1
Quick topix 11/7/13 CSE 1102 Fall 2013
2
previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________ loop A.Do-while B.For C.While [CORRECT] D.If E.Loop dee
3
previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________ loop A.Do-while B.For [CORRECT] C.While D.If E.Loop dee
4
previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________ loop A.Do-while [CORRECT] B.For C.While D.If E.Loop dee
5
previous statement Execute rest of program Is true? yes no... while ( )... while (time > 0) { System.out.println(time); time = time – 1; }...
6
previous statement Execute rest of program Is true? yes no Alter... for ( ; ; )... for (int i = 0; i< _balls.length; i++) _balls[i].fill(aBetterBrush);...
7
previous statement Execute rest of program Is true? yes no... do while ( )... do { aCookieBag.add(new Cookie()); numCookies++; } while (numCookies < _myLunchNeeds);...
8
Mouse Adapters
9
Suppose we want to add a MouseListener or MouseMotionListener in JPanel, e.g., we have public void addMouseListener(MouseListener m); public interface MouseListener extends EventListener { void mouseClicked (MouseEvent e); void mouseEntered (MouseEvent e); void mouseExited (MouseEvent e); void mousePressed (MouseEvent e); void mouseReleased (MouseEvent e); } e.g., _myPanel.addMouseListener(new MyMouseListener(this));
10
Answer: MouseAdapter public interface MouseListener extends EventListener { void mouseClicked (MouseEvent e); void mouseEntered (MouseEvent e); void mouseExited (MouseEvent e); void mousePressed (MouseEvent e); void mouseReleased (MouseEvent e); } public class MouseAdapter implements MouseListener { public void mouseClicked (MouseEvent e){} public void mouseEntered (MouseEvent e){} public void mouseExited (MouseEvent e){} public void mousePressed (MouseEvent e) {} public void mouseReleased (MouseEvent e){} }
11
A.A subclass of an existing class is faster than a new class that implements the interface. B.The MouseAdapter code has been debugged. [CORRECT] C.You don't have to define all of the methods [CORRECT] D.There is no advantage if you need all of the methods in MouseListener [CORRECT] E.More than one of the above are true [CORRECT] What advantage is there in extending MouseAdapter over implementing MouseListener when defining a MouseListener class?
12
Arrays
13
Using an array Declare it: private Peg[] _pegs; _pegs Instantiate it: _pegs = new Peg[10]; Instantiate its elements: for (int i=0;i<5;i++) _pegs[i] = new Peg();
14
A._pegs.length causes a run-time error [CORRECT] B._pegs.length is 0, and the number of Pegs in the array is 0. C._pegs.length is 10, and the number of Pegs in the array is 0. D._pegs.length is 10, and the number of Pegs in the array is 5. E._pegs.length is 5, and the number of Pegs in the array is 5. After the Declare step, which of the following is true? Declare it: private Peg[] _pegs;
15
A._pegs.length causes a run-time error B._pegs.length is 0, and the number of Pegs in the array is 0. C._pegs.length is 10, and the number of Pegs in the array is 0. [CORRECT] D._pegs.length is 10, and the number of Pegs in the array is 5. E._pegs.length is 5, and the number of Pegs in the array is 5. After the Instantiate step, which of the following is true? Instantiate it: _pegs = new Peg[10];
16
A._pegs.length causes a run-time error B._pegs.length is 0, and the number of Pegs in the array is 0. C._pegs.length is 10, and the number of Pegs in the array is 0. D._pegs.length is 10, and the number of Pegs in the array is 5. [CORRECT] E._pegs.length is 5, and the number of Pegs in the array is 5. After the Instantiate its elements step, which of the following is true? Instantiate its elements: for (int i=0;i<5;i++) _pegs[i] = new Peg();
17
Clicker questions 11/6/12 CSE 1102 Fall 2012
18
_pegs In getting from left to right… A. _pegs.addToLength(5); B. _pegs = new Peg[10]; C. Peg temp = new Peg[10] D. _pegs[i] = temp[i]; E. temp[i] = _pegs[i]; [CORRECT (B and D could also be, however, but not in my code – next slide)] Which line below will appear in the code?
19
_pegs temp Declare: Pegs[] temp; Instantiate array: temp = new Pegs[2 * _pegs.length]; Instantiate elements: for (int i=0;i<_pegs.length) temp[i] = _pegs[i]; Reassign variable: _pegs = temp;
20
A. The array _balls is unchanged B. The first element of _balls is a new Ball constructed using new Ball(Color.pink) and not the same as _moreBalls[0]; C. _balls[0] == _moreBalls[0]; [CORRECT] D. 0, numberOfBalls – 1 E. _balls.length is undefined 1.public BallPanel extends javax.swing.Panel { 2.private Ball[] _balls; 3. private Ball[] _moreBalls; 4.public BallPanel(int numberOfBalls){ 5._balls = new Ball[numberOfBalls]; 6.for (int i=0;i<_balls.length;i++) 7._balls[i] = new Ball(); 8. _moreBalls = _balls; 9.} Suppose we instantiate BallPanel as follows: BallPanel myPanel = new BallPanel(5); Which of the following statements is true, after executing _moreBalls[0] = new Ball(Color.pink); in some other method of BallPanel ?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.