Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Which package is the Graphics class part of? _________________ . a. javax.swi

ID: 666953 • Letter: 1

Question

1. Which package is the Graphics class part of? _________________ .

a. javax.swing

b. java.swing

c. java.awt

d. javax.awt

e. java.graphics

2. The name of the method used to set the current color is _________________

3. Complete the code, drawing a line between points (100, 200) and (34, 67)

public void paint( Graphics g )

{

// your code goes here

}

4. Complete the code, drawing a solid circle (with the current color, whatever it is) so that its diameter is 200, and the coordinates of its center are ( 250, 150 )

public void paint( Graphics g )

{

// your code goes here

}

5. The access modifier of constructors should be _________________

6. When you use a while loop to compute the product of several values, you should initialize the variables holding the product to ______ .

a. 0

b. 1

c. NULL

d. there is no need to initalize it

7. When a loop condition is grade >= 90, what values would you use to test your loop?

a. 88 and 89

b. 0 and 90

c. 89, 90 and 91

d. 90, 91 and 92

8. What is the output of this code sequence?

for ( int i = 5; i >= 0; i-- )

System.out.print( i + " " );

System.out.println( );

9. Write a loop to output the word EXAM 99 times

10. To access the number of elements in an array named grades, we use _________________ .

  a. grades

  b. grades.size()

  c. grades.size

  d. grades.length()

  e. grades.length

11. Write the code to compute and output how many times the value 99 is found in an array of integers named numbers

12. When processing all the elements of row i of a two-dimensional array named grades using a for loop with variable j, what is the condition of the for loop? _________________ .

a. j < length

b. j < grades.length

c. j < = grades.length

d. j < grades [i].length

e. j < = grades [i].length

13. The variable numbers is a 2-dimensional array of type int; output all of its elements that are strictly greater than 10

14. What is the error and why is there an error in the code below?

public class XYZ

{

public static final int A = 9;

public abstract void foo1( );

public int foo2( )

{

return 5;

}

}

15. When we read objects from a file using the readObject method, what happens when the end of the file is reached?

16. What is the output of the following sequence?

Scanner scan = new Scanner( System.in );

int number = 0;

try

{

number = scan.nextInt( );    // User enters 12, hits ENTER

System.out.println( "1: " + number );

number = scan.nextInt( );    // User enters 56, hits ENTER

System.out.println( "2: " + number );

number = scan.nextInt( );     // User enters 99ABC, hits ENTER

System.out.println( "3: " + number );

}

catch( Exception e)

{

String s = scan.nextLine( );

System.out.println( "4: " + number );

}

finally

{

number = scan.nextInt( ); // User enters 100, hits ENTER

System.out.println( "5: " + number );

}

17. In the BorderLayout class, what are NORTH, SOUTH, EAST, WEST, and CENTER?

Explanation / Answer

1)

c. java.awt

2)

For example, if the user input string equals "red", you should set the ColorPanel's background color to red and set the current color state to RED (Recall that RED is a String constant whose value is the String "red"). Of course you need to do the same for inputs "green" and "blue".

3)   import javax.swing.JFrame;

import java.awt.Graphics;

import javax.swing.JPanel;

import java.awt.Color;

import javax.swing.JLabel;

import javax.swing.ImageIcon;

import java.awt.BorderLayout;

public DrawPanel()                       // set up graphics window

{

super();

setBackground(Color.WHITE);

}

public void paint( Graphics g )

{

int start_x-coordinate=100;

int start_y-coordinate=200;

int end_x-coordinate=34;

int end_y-coordinate=67;

System.out.println("The values of cordinates are" "("+start_x-coordinate","+start_y-coordinate")" "and" "("+end_x-coordinate","+end_y-coordinate")" ;

g.drawLine( start_x-coordinate , start_y-coordinate , end_x-coordinate , end_y-coordinate );

}

6) b. 1

7)   d. 90, 91 and 92

8) System.out.println( );

10) b. grades.size()

12) c. j < = grades.length

1)

c. java.awt

2)

For example, if the user input string equals "red", you should set the ColorPanel's background color to red and set the current color state to RED (Recall that RED is a String constant whose value is the String "red"). Of course you need to do the same for inputs "green" and "blue".