If we want to write a program to display the word

This preview shows page 11 - 15 out of 33 pages.

18. If we want to write a program to display the word "hello" to the output window when the key labelled 'h' on the keyboard is pressed, how might we define our keyPressed() method? (a) public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 'h') System.out.println("hello"); } (b) public void keyPressed(KeyEvent e) { if (e.getKeyChar() == 'h') System.out.println("hello"); } (c) public void keyPressed(KeyEvent e) { if (e.getKeyChar() == "h") System.out.println("hello"); } (d) public void keyPressed(KeyEvent e) { if (e.getKeyCode() == "h") System.out.println("hello"); } (e) None of the above 19. Consider a Line class which represents a line with a starting point, a length, and either a horizontal or vertical orientation. The following instance variables are defined in the Line class: public class Line { private int x, y; private int length; private boolean isHorizontal; ... } Here, x and y specify the upper most, left most end point of the line, length is the length of the line, and isHorizontal is true if the line is horizontal and false otherwise. How might an includes() method be defined in the Line class, so that the method returns true if a specified position lies somewhere on the line, and false otherwise? The specified position is passed to the method as parameters testX and testY .
Image of page 11

Subscribe to view the full document.

VERSION 1 - 12 - COMPSCI 101 Question/Answer Sheet ID ........................................ CONTINUED
Image of page 12
VERSION 1 - 13 - COMPSCI 101 Question/Answer Sheet ID ........................................ CONTINUED 20. What is the output of the following nested loop? for (int i = 0; i < 4; i++) for (int j = i; j > 1; j--) System.out.println(i + " " + j);
Image of page 13

Subscribe to view the full document.

VERSION 1 - 14 - COMPSCI 101 Question/Answer Sheet ID ........................................ CONTINUED The following information is used by questions 21 and 22. Consider the following screenshots for a program which processes mouse events. When the program first starts, the window is initially empty. The first time the mouse button is pressed, nothing appears on the window The second time the mouse is pressed, a line is drawn from the location of the first mouse press to the location of the new mouse press The third time the mouse is pressed a triangle is drawn connecting the first three presses of the mouse button The fourth time the mouse is pressed, nothing visible changes on the window The fifth time the mouse is pressed, a line is drawn from the location of the fourth mouse press to the location of the new mouse press
Image of page 14
Image of page 15
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, ........., Types of chocolate, mouse press

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern