1. (TCOs 1–8) Given a graphics object

g,

to draw a polygon to connect points (3, 3), (4, 10), (10, 20), (2, 100), you use _____ (Points : 3)

g.drawPolygon({3, 4, 10, 2}, {3, 10, 20, 100}, 4).

g.drawPolyline(new int[ ]{3, 4, 10, 2}, new int[ ]{3, 10, 20, 100}, 4).

g.drawPolygon(new int[ ]{3, 4, 10, 2}, new int[ ]{3, 10, 20, 100}, 4).

g.drawPolyline({3, 4, 10, 2}, {3, 10, 20, 100}, 4).

 

2. (TCOs 1–8) To create an image object from an ImageIcon object imageIcon, use the _____ method. (Points : 3)

imageIcon.returnImage()

imageIcon.getImage()

imageIcon.setImage()

imageIcon.image()

 

3. (TCOs 1–8) Which type of exception occurs when creating a DataInputStream for a nonexistent file? (Points : 3)

FileNotExist

FileNotFound

FileNotExistException

FileNotFoundException

 

 

4. (TCOs 1–8) After the following program is finished, how many bytes are written to the file t.dat?

import java.io.*;

public class Test {

  public static void main(String[ ] args) throws IOException {

    DataOutputStream output = new DataOutputStream(

      new FileOutputStream("t.dat"));

    output.writeChars("ABCD");

    output.close();

  }

} (Points : 3)

16 bytes

12 bytes

4 bytes

2 bytes

8 bytes

 

5. (TCOs 1–8) The coordinate of the upper-left corner of a frame is _____ (Points : 3)

(100, 100).

(10, 10).

(0, 0).

(25, 25).

 

6. (TCOs 1–8) Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code.

Scanner scanner = new Scanner(System.in);

int intValue = scanner.nextInt();

int doubleValue = scanner.nextInt();

String line = scanner.nextLine(); (Points : 3)

After the last statement is executed, line contains characters '7', '8', '9'.

After the last statement is executed, line contains characters '7', '8', '9', '\n'.

After the last statement is executed, intValue is 34.

The program has a runtime error because 34.3 is not an integer.

 

7. (TCOs 1–8) What is displayed by the following code?

  public static void main(String[ ] args) throws Exception {

    String[ ] tokens = "Welcome to Java".split("o");

    for (int i = 0; i < tokens.length; i++) {

      System.out.print(tokens[i] + " ");

    }

  } (Points : 3)

Welc me t  Java

Welcome to Java

Welcome t  Java

Welc me to Java

 

 

8. (TCOs 1–8) Suppose you enter 34.3 57.8 789,

then press the ENTER key. Analyze the following code.

Scanner scanner = new Scanner(System.in);

int value = scanner.nextDouble();

int doubleValue = scanner.nextInt();

String line = scanner.nextLine(); (Points : 3)

After the last statement is executed, intValue is 34.

After the last statement is executed, line contains characters '7', '8', '9', '\n'.

After the last statement is executed, line contains characters '7', '8', '9'.

The program has a runtime error because 34.3 is

 not an integer.

 

9. (TCOs 1–8) Which class do you use to read data into a text file? (Points : 3)

Scanner

System

PrintWriter

File

 

10. (TCOs 1–8) Which of the following is the correct statement to return

 a string from an array a of characters? (Points : 3)

convertToString(a)

toString(a)

new String(a)

String.toString(a)

 

 

    • 11 years ago
    A+ Answers
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      ksfile24.docx