Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 83 pages
Exam (elaborations)

CS 1114 TEST 2 QUESTION COMPLETE WITH VERIFIED ANSWERS

Document preview thumbnail
Preview 4 out of 83 pages

CS 1114 TEST 2 QUESTION COMPLETE WITH VERIFIED ANSWERS Q.Consider this code segment: String one = "1"; String two = "2"; String three = "3"; String four = "4"; ArrayListString aList = new ArrayListString(); aL(one); aL(two); aL(three); aL(four); What output is printed by the following statements? aLe(1); aL("5"); Sln(aL(1)); an error occurs 1 2 3 none of these 5 4 - ANSWERS-3 Q.Consider the following code segment: int w = 0; for (int x = 0; x 5; x++) { w = -1; for (int y = 1; y x; y++) { w = w + y; } } Sln(w); What value is printed? 1 2 0 4 -1 None of these 5 3 8 6 7 - ANSWERS-5 Q.Consider your lab assignment when reviewing the following code that will be placed in the CopyingJeroo class: public void atFlower() { if (Flower(HERE)) { (); (); } } What would happen if this code was integrated in your solution? The image would be removed from both islands. The image would only be on the first island. The image would be present on both islands. The image would be created on the second island and removed from the first island. - ANSWERS-The image would be created on the second island and removed from the first island. Q.Consider this code segment: boolean x = false; boolean y = true; boolean z = true; Sln( (x || !y) && (!x || z) ); What value is printed? Nothing, there is a syntax error false true - ANSWERS-false Q.Suppose I have written the following code: List earlyTimes = new ArrayList(); earlyT("1pm"); List otherTimes = new ArrayList(); otherT("1pm"); if (/* missing condition */) { Sln("You look great!"); //indicated line } Which of the following conditions will cause the indicated line to be executed? earlyTs("1pm") earlyTs(otherTimes) earlyTimes == "1pm" earlyTimes == otherTimes - ANSWERS-earlyTs(otherTimes) Q.Note: This question deals with material from chapter 6. What is a boolean method (also known as a predicate)? Any method that produces a number as a result. Any method that produces an object as a result. Any method that doesn't return a result. Any method that produces either true or false as a result. - ANSWERS-Any method that produces either true or false as a result. Q.Which of the following access modifiers enforces information hiding? hidden private open public - ANSWERS-private Q.int sum = 0; for (int i = 1; i 4; i++)

Content preview

CS 1114 TEST 2 QUESTION COMPLETE WITH
VERIFIED ANSWERS



\Q\.Consider this code segment:



String one = "1";

String two = "2";

String three = "3";

String four = "4";

ArrayList<String> aList = new ArrayList<String>();

aList.add(one);

aList.add(two);

aList.add(three);

aList.add(four);



What output is printed by the following statements?

aList.remove(1);

aList.add("5");

System.out.println(aList.get(1));



an error occurs

1

2

,3

none of these

5

4 - ANSWERS✔-3



\Q\.Consider the following code segment:



int w = 0;

for (int x = 0; x < 5; x++)

{

w = -1;

for (int y = 1; y < x; y++)

{

w = w + y;

}

}

System.out.println(w);

What value is printed?



1

2

0

4

-1

None of these

5

,3

8

6

7 - ANSWERS✔-5



\Q\.Consider your lab assignment when reviewing the following code that will be placed in the
CopyingJeroo class:



public void atFlower()

{

if (this.seesFlower(HERE))

{

copier.plant();

this.pick();

}

}

What would happen if this code was integrated in your solution?



The image would be removed from both islands.

The image would only be on the first island.

The image would be present on both islands.

The image would be created on the second island and removed from the first island. -
ANSWERS✔-The image would be created on the second island and removed from the first
island.



\Q\.Consider this code segment:

, boolean x = false;

boolean y = true;

boolean z = true;



System.out.println( (x || !y) && (!x || z) );

What value is printed?

Nothing, there is a syntax error

false

true - ANSWERS✔-false



\Q\.Suppose I have written the following code:



List earlyTimes = new ArrayList();

earlyTimes.add("1pm");



List otherTimes = new ArrayList();

otherTimes.add("1pm");



if (/* missing condition */)

{

System.out.println("You look great!"); //indicated line

}

Which of the following conditions will cause the indicated line to be executed?




earlyTimes.equals("1pm")

Document information

Uploaded on
January 15, 2026
Number of pages
83
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
IszackBd
5.0
(3)
Sold
40
Followers
3
Items
5715
Last sold
7 hours ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions