Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Which of the following is NOT one of the three categories of collections we have studied? 1 Map 2 Set 3 Iterator 4

Question 1 Which of the following is NOT one of the three categories of collections we have studied?

1 Map

2 Set

3 Iterator

4 List

Flag this Question Question 2 Which of the following is NOT a wrapper class?

1 String

2 Integer

3 Character

4 Double

Flag this Question Question 3 Which of the following kinds of things may be stored directly in an ArrayList?

1 primitive values

2 object references

3 None of the above

4 Either of these two kinds of data

Flag this Question Question 4 In this declaration: ArrayList polygon; what do we call 'Point'?

1 a variable

2 a collection

3 a type argument

4 a wrapper class

Flag this Question Question 5 In this declaration: ArrayList polygon; what is the data type of the variable 'polygon'?

1 Array

2 ArrayList

3 Point

4 ArrayList

5 None of the above

Flag this Question Question 6 If this method call: myList.size() returns the value 7, what is the range of legal values allowed for the variable x in the following method call? myList.get( x )

1 x may be any int value

2 1 thru 7

3 0 thru 7

4 0 thru 6

Flag this Question Question 7

Assume that the following code has been executed (same for Questions 7 thru 10):

ArrayList plot = new ArrayList(); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) ); What value is returned by the following expression? plot.size()

1 5

2 4

3 0

4 2

5 3

Flag this Question Question 8

Assume that the following code has been executed (same for Questions 7 thru 10):

ArrayList plot = new ArrayList(); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) ); Which Point is returned by the following expression? plot.get( 1 )

1 0,0

2 12,16

3 5,10

4 None -- the statement throws a runtime exception

5 4,8

Flag this Question Question 9

Assume that the following code has been executed (same for Questions 7 thru 10):

ArrayList plot = new ArrayList(); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) ); Which Point is returned by the following expression? plot.get( 2 )

1 12,16

2 -5,5

3 4,8

4 None -- the statement throws a runtime exception

5 0,0

Flag this Question Question 10

Assume that the following code has been executed (same for Questions 7 thru 10):

ArrayList plot = new ArrayList(); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) ); Which Point is returned by the following expression? plot.get( 5 )

1 -5,5

2 The value null is returned

3 5,10

4 4,8

5 None -- the statement throws a runtime exception

Flag this Question Question 11

Assume that the following code has been executed (same for Questions 11 thru 14):

ArrayList nums = new ArrayList(); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size() ; int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 ); What is the value of the variable 's'?

1 4

2 7

3 5

4 6

5 2

Flag this Question Question 12

Assume that the following code has been executed (same for Questions 11 thru 14):

ArrayList nums = new ArrayList(); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 ); What is the value of the variable 'sum'?

1 76

2 15

3 78

4 50

5 26

Flag this Question Question 13

Assume that the following code has been executed (same for Questions 11 thru 14):

ArrayList nums = new ArrayList(); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 ); How many elements remain on the list when the code is finished executing?

1 4

2 5

3 1

4 7

5 6

Flag this Question Question 14

Assume that the following code has been executed (same for Questions 11 thru 14):

ArrayList nums = new ArrayList(); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 ); What is the value of the first element remaining on the list?

1 12

2 15

3 6

4 11

5 32

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago