CIS 265 - Fall 2014 Exam-1 (Review)

CIS 265 - Fall 2014 Exam-1 (Review)

Fist Name______Last Name______

MULTIPLE CHOICE. (25points) Choose the one alternative that best completes the statement or answers the question.

1)

The following code displays ______.

double temperature = 50;

if (temperature >= 100)

System.out.println("too hot");

else if (temperature <= 40)

System.out.println("too cold");

else

System.out.println("just right");


1)

______

A)

just right

B)

too cold

C)

too hot

D)

too hot too cold just right

2)

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

2)

______

A)

(1 > x > 100) || (x < 0)

B)

1 < x < 100 & x < 0

C)

((x < 100) & (x > 1)) & (x < 0)

D)

((x < 100) & (x > 1)) || (x < 0)

3)

To check whether a char variable ch is an uppercase letter, you write ______.

3)

______

A)

(ch >= 'A' & ch >= 'Z')

B)

(ch >= 'A' & ch <= 'Z')

C)

('A' <= ch <= 'Z')

D)

(ch >= 'A' || ch <= 'Z')

4)

What is the output for y?

int y = 0;

for (int i = 0; i<10; ++i) {

y += i;

}

System.out.println(y);


4)

______

A)

12

B)

45

C)

11

D)

13

E)

10

5)

What is sum after the following loop terminates?

int sum = 0;

int item = 0;

do {

item++;

sum += item;

if (sum >= 4) continue;

}

while (item < 5);


5)

______

A)

16

B)

15

C)

17

D)

18

6)

If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ______.

6)

______

A)

0

B)

2

C)

1

D)

4

E)

3

7)

If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ______.

7)

______

A)

2.0

B)

3.4

C)

5.5

D)

3.4

E)

undefined


8)

In the following code, what is the printout for list2?

class Test {

public static void main(String[ ] args) {

int[ ] list1 = {1, 2, 3};

int[ ] list2 = {1, 2, 3};

list2 = list1;

list1[0] = 0; list1[1] = 1; list2[2] = 2;

for (int i = 0; i list2.length; i++)

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

}

}


8)

______

A)

1 2 3

B)

0 1 2

C)

1 1 1

D)

0 1 3

9)

______represents an entity in the real world that can be distinctly identified.

9)

______

A)

An object

B)

A data field

C)

A method

D)

A class

10)

Analyze the following code:

public class Test {

public static void main(String[ ] args) {

int[ ] x = {1, 2, 3, 4};

int[ ] y = x;

x = new int[2];

for (int i = 0; i y.length; i++)

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

}

}


10)

______

A)

The program displays 0 0 0 0

B)

The program displays 0 0

C)

The program displays 1 2 3 4

D)

The program displays 0 0 3 4

11)

______is a construct that defines objects of the same type.

11)

______

A)

A class

B)

A data field

C)

A method

D)

An object

12)

An object is an instance of a ______.

12)

______

A)

data

B)

program

C)

class

D)

method

13)

______is invoked to create an object.

13)

______

A)

A constructor

B)

A method with the void return type

C)

The main method

D)

A method with a return type

14)

Given the declaration Circle[ ] x = new Circle[10], which of the following statement is most accurate?

14)

______

A)

x contains a reference to an array and each element in the array can hold a reference to a Circle object.

B)

x contains a reference to an array and each element in the array can hold a Circle object.

C)

x contains an array of ten objects of the Circle type.

D)

x contains an array of ten int values.

15)

What is the output of the following code?

String s = "University";

s.replace("i", "ABC");

System.out.println(s);


15)

______

A)

University

B)

UnABCversity

C)

UniversABCty

D)

UnABCversABCty

16)

You can create an ArrayList using ______.

16)

______

A)

new ArrayList[100]

B)

new ArrayList[ ]

C)

ArrayList()

D)

new ArrayList()

17)

Object-oriented programming allows you to derive new classes from existing classes. This is called ______.

17)

______

A)

abstraction

B)

generalization

C)

encapsulation

D)

inheritance

18)

What is the return value of "SELECT".substring(0, 5)?

18)

______

A)

"SELECT"

B)

"SELE"

C)

"SELEC"

D)

"ELECT"

19)

Invoking ______removes all elements in an ArrayList x.

19)

______

A)

x.clean()

B)

x.remove()

C)

x.delete()

D)

x.clear()

E)

x.empty()

20)

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]?

20)

______

A)

x.add(1, "Chicago")

B)

x.add(0, "Chicago")

C)

x.add(2, "Chicago")

D)

x.add("Chicago")

21)

Invoking ______returns the first element in an ArrayList x.

21)

______

A)

x.get(1)

B)

x.get()

C)

x.get(0)

D)

x.first()

22)

Invoking ______returns the number of the elements in an ArrayList x.

22)

______

A)

x.length(1)

B)

x.size()

C)

x.getSize()

D)

x.getLength(0)

23)

Inheritance means ______.

23)

______

A)

that data fields should be declared private

B)

that a variable of supertype can refer to a subtype object

C)

that a class can extend another class

D)

that a class can contain another class

24)

Composition means ______.

24)

______

A)

that a class can contain another class

B)

that data fields should be declared private

C)

that a variable of supertype can refer to a subtype object

D)

that a class can extend another class

25)

Encapsulation means ______.

25)

______

A)

that a class can contain another class

B)

that a variable of supertype can refer to a subtype object

C)

that data fields should be declared private

D)

that a class can extend another class


CIS 265 - Fall 2012 Exam-1

Fist Name______Last Name______

(25 points) JAVA PROGRAMMING

Write a method to determine whether or not two strings are an anagram. Assume the strings only contain letters and spaces. Any two words or phrases that exactly include the same letters are called an anagram. For instance: “dad ” and “ add”, “stressed” and “desserts”, “George Bush” and “He bugs Gore”. Your method must not be case sensitive.

The signature of the method follows:

public static boolean isAnagram (String s1, String s2)


1)

A

2)

D

3)

B

4)

B

5)

B

6)

E

7)

A

8)

B

9)

A

10)

C

11)

A

12)

C

13)

A

14)

A

15)

A

16)

D

17)

D

18)

C

19)

D

20)

A

21)

C

22)

B

23)

C

24)

A

25)

C

Exam 1 KEY

1) A 2) D 3) B 4) B 5) B 6) E 7) A 8) B 9) A 10) C

11) A 12) C 13) A 14) A 15) A 16) D 17) D 18) C 19) D 20) A

21) C 22) B 23) C 24) A 25) C