Download CIS 265 - Spring 2015 Exam

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CIS 265 - Spring 2015
Exam-1
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 ________.
1) _______
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");
A) just right
C) too hot
B) too cold
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?
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)
2) _______
3) To check whether a char variable ch is an uppercase letter, you write ________.
A) (ch >= 'A' && ch >= 'Z')
B) (ch >= 'A' && ch <= 'Z')
C) ('A' <= ch <= 'Z')
D) (ch >= 'A' || ch <= 'Z')
3) _______
4) What is the output for y?
4) _______
int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
System.out.println(y);
A) 12
B) 45
C) 11
D) 13
E) 10
5) What is sum after the following loop terminates?
5) _______
int sum = 0;
int item = 0;
do {
item++;
sum += item;
if (sum >= 4) continue;
}
while (item < 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
________.
A) 0
B) 2
C) 1
D) 4
E) 3
6) _______
7) If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.
A) 2.0
B) 3.4
C) 5.5
D) 3.4
E) undefined
7) _______
8In 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] + " ");
}
}
A) 1 2 3
B) 0 1 2
8) _______
C) 1 1 1
D) 0 1 3
9) ________ represents an entity in the real world that can be distinctly identified.
A) An object
B) A data field
C) A method
D) A class
10) Analyze the following code:
9) _______
10) ______
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] + " ");
}
}
A) The program displays 0 0 0 0
C) The program displays 1 2 3 4
B) The program displays 0 0
D) The program displays 0 0 3 4
11) ________ is a construct that defines objects of the same type.
A) A class
B) A data field
C) A method
D) An object
12) An object is an instance of a ________.
A) data
B) program
11) ______
12) ______
C) class
D) method
13) ________ is invoked to create an object.
A) A constructor
B) A method with the void return type
C) The main method
D) A method with a return type
13) ______
14) Given the declaration Circle[ ] x = new Circle[10], which of the following statement is most
accurate?
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.
14) ______
15) What is the output of the following code?
15) ______
String s = "University";
s.replace("i", "ABC");
System.out.println(s);
A) University
C) UniversABCty
B) UnABCversity
D) UnABCversABCty
16) You can create an ArrayList using ________.
A) new ArrayList[100]
C) ArrayList()
16) ______
B) new ArrayList[ ]
D) new ArrayList()
17) Object-oriented programming allows you to derive new classes from existing classes. This
is called ________.
A) abstraction
B) generalization
C) encapsulation
D) inheritance
17) ______
18) What is the return value of "SELECT".substring(0, 5)?
A) "SELECT"
B) "SELE"
C) "SELEC"
D) "ELECT"
18) ______
19) Invoking ________ removes all elements in an ArrayList x.
A) x.clean()
B) x.remove()
C) x.delete()
D) x.clear()
E) x.empty()
19) ______
20) Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following
methods will cause the list to become [Beijing, Chicago, Singapore]?
A) x.add(1, "Chicago")
B) x.add(0, "Chicago")
C) x.add(2, "Chicago")
D) x.add("Chicago")
20) ______
21) Invoking ________ returns the first element in an ArrayList x.
A) x.get(1)
B) x.get()
C) x.get(0)
21) ______
D) x.first()
22) Invoking ________ returns the number of the elements in an ArrayList x.
A) x.length(1)
B) x.size()
C) x.getSize()
D) x.getLength(0)
22) ______
23) Inheritance means ________.
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
23) ______
24) Composition means ________.
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
24) ______
25) Encapsulation means ________.
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
25) ______
(25 points)
JAVA PROGRAMMING
Write a Java method to accept an ArrayList of String values. It must return a new ArrayList holding those words taken from the
original list that include two or more occurrences of the character ‘e’.
For example, if the input list consists of the words [“alpha”, “Parma”, “Daenerys”, “Dragons”, “Westeros”] your method should
return [“Daenerys”, “Westeros”].
Your solution should work for any list of words (not just the sample given here)
public static ArrayList<String> selectWordsMultipleE ( ArrayList<String> list ) {
(25 points)
JAVA PROGRAMMING
Write a Java method to accept an ArrayList holding Integer numbers. It must return a new ArrayList holding the elements
larger than the average value of the numbers supplied in the original list.
For example, if the input list consists of [55, 22, 44, 11, 33] its average value is 33. Therefore your method should return [44, 55].
Your solution should work for any list of integers (not just the sample given here)
public static ArrayList<Integer> largerThanAverage ( ArrayList<Integer> list ) {
1)
2)
3)
4)
5)
6)
7)
8)
9)
10)
11)
12)
13)
14)
15)
16)
17)
18)
19)
20)
21)
22)
23)
24)
25)
A
D
B
B
B
E
A
B
A
C
A
C
A
A
A
D
D
C
D
A
C
B
C
A
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