Upload
ada-dennis
View
212
Download
0
Embed Size (px)
DESCRIPTION
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
Citation preview
Quick topix11/7/13
CSE 1102 Fall 2013
previous statement
Execute <loop body>
rest of program
Is <loop condition>
true?
yes
no
This flowchart illustrates the logic of a _________ loop
A. Do-while
B. For
C. While [CORRECT]
D. If
E. Loop dee
previous statement
Execute <loop body>
rest of program
Is <loop condition>
true?
yes
no
<assign value to counter>
<alter counter>
This flowchart illustrates the logic of a _________ loop
A. Do-while
B. For [CORRECT]
C. While
D. If
E. Loop dee
previous statement
Execute <loop body>
rest of program
Is <loop condition>
true?
yes
no
This flowchart illustrates the logic of a _________ loop
A. Do-while [CORRECT]
B. For
C. While
D. If
E. Loop dee
previous statement
Execute <loop body>
rest of program
Is <loop condition>
true?
yes
no
...while (<loop condition>) <loop body>
...
...while (time > 0) { System.out.println(time); time = time – 1; }...
previous statement
Execute <loop body>
rest of program
Is <loop condition>
true?
yes
no
<assign value to counter>
Alter <counter>
...for (<assign value to counter>; <loop condition>; <alter counter>) <loop body>
...
...for (int i = 0; i< _balls.length; i++) _balls[i].fill(aBetterBrush);...
previous statement
Execute <loop body>
rest of program
Is <loop condition>
true?
yes
no
...do <loop body>while (<loop condition>)
...
...do { aCookieBag.add(new Cookie()); numCookies++; }while (numCookies < _myLunchNeeds);...
Mouse Adapters
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));
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){}}
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?
Arrays
Using an arrayDeclare 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();
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;
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];
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();
Clicker questions11/6/12
CSE 1102 Fall 2012
_pegs _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?
_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;
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?