The Number of Characters in an Object of a Class String Is Given By

1. [1 Point]

Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class.

2. [1 Point]

Is the following statement true or false. The constructor of a class must not have a return type.

A.  true

B.  false

3. [1 Point]

The number of characters in an object of a class String is given by

A.  The member variable called size

B.  The member variable called length

C.  The method size() returns the number of characters.

D.  The method length() returns the number of characters.

4. [1 Point]

What is the index of Brighton in the following array?

String[] skiResorts = {

"Whistler Blackcomb", "Squaw Valley", "Brighton", "Snowmass", "Sun Valley", "Taos"

};

5. [2 Points]

Which of the following is a Java keyword. Select the two correct answers.

A.  void

B.  friendly

C.  comment

D.  this

E.  then

6. [3 Points]

Which of the following are legal array declarations. Select the three correct answers.

A.  int i[5][];

B.  int i[][];

C.  int []i[];

D.  int i[5][5];

E.  int[][] a;

7. [3 Points]

What gets printed when the following is compiled and run?

public class test {

public static void main(String args[]) {

int i=0, j=2;

do {

i=++i;

j--;

} while(j>0);

System.out.println(i);

}

}

8. [3 Points]

What is the result of the following operation?

12/3+12*4-3

9. [4 Points]

What is the value of a?

inta=7;
intb=4;
a=b;
a=a+1;

10. [5 Points]

Please write a one-line expression that tests whether a previously declared double variable with the identifier value does not equal 5.65.

11. [5 Points]

What output is produced by the following program:

·  A. A compiler error.

·  B. A runtime error.

·  C. 10

·  D. 20

class Q11{

public static void main(String args[]){

long size = 10;

int[] array = new int[size];

size = 20;

System.out.println(array.length);

}//end main()

}//end class definition

12. [7 Points]

Write a method with the following signature that displays “Hello” to the screen “i” times (the number of times given by the parameter):

public void display (int i) {

// your code goes here

}

13. [14 Points]

Suppose that A has been declared and initialized with the statement

int[] A = new int[20];

Write a program that will return the smallest and the largest value in the array.

14. [24 Points]

Suppose that A has been declared and initialized with the statement

double[] A = new double[20];

And suppose that A has already been filled with 20 values. Write a program segment that will find the average of all the non-zero numbers in the array. (The average is the sum of the numbers, divided by the number of numbers. Note that you will have to count the number of non-zero entries in the array.) Declare any variables that you use.

15. [26 Points]

Suppose that a class, Employee, is defined as follows:

class Employee {

String lastName;

String firstName;

double hourlyWage;

int yearsWithCompany;

}

Suppose that data about 100 employees is already stored in an array:

Employee[] employeeData = new Employee[100];

Write a code segment that will output the first name, last name, and hourly wage of each employee who has been with the company for 20 years or more.