20
Quick topix 11/7/13 CSE 1102 Fall 2013

Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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

Page 1: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

Quick topix11/7/13

CSE 1102 Fall 2013

Page 2: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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

Page 3: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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

Page 4: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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

Page 5: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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; }...

Page 6: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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);...

Page 7: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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);...

Page 8: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

Mouse Adapters

Page 9: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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));

Page 10: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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){}}

Page 11: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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?

Page 12: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

Arrays

Page 13: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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();

Page 14: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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;

Page 15: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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];

Page 16: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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();

Page 17: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

Clicker questions11/6/12

CSE 1102 Fall 2012

Page 18: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

_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?

Page 19: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

_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;

Page 20: Quick topix 11/7/13 CSE 1102 Fall 2013. previous statement Execute rest of program Is true? yes no This flowchart illustrates the logic of a _________

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?