Docsity

Quiz Questions on Java Lists and ArrayLists - Prof. Mark Weiss, Quizzes of Data Structures and Algorithms

Toggle sidebar
bg1
Quiz #1B
Name
:
READ THE QUESTIONS CAREFULLY!!! DO NOT WASTE TIME DOING
MORE THAN IS ASKED FOR. DO NOT IMPLEMENT METHODS UNLESS SPECI-
FICIALLY REQUESTED. YOU DO NOT NEED TO COMMENT THE CODE.
YOU MAY USE
T
INSTEAD OF
AnyType
. IN QUESTION 2 IF YOU INVOKE AN
ARRAYLIST METHOD YOU MUST SHOW THE IMPLEMENTATION OF THE
METHOD.
1. Write an
interfae
op3530.List
with the publi methods below. (This is a dierent inter-
fae than what you wrote for program 1, but the priniples are idential.)
List
is the name of
the
generi interfae
that stores identially typed items and has the following funtionality:
Three aessors:
ontains
returns true if a speied ob jet is found in the set; returns
false otherwise.
isEmpty
, tests if the
List
is empty; and
size
returns the number of
elements urrently stored in the
List
ontainer.
Two mutators: One makes the
List
empty; the other (
add
) inserts a new item.
2. Provide a
generi
lass
op3530.ArrayList
that implements the
List
interfae. Represent
the
ArrayList
internally as a primitive array, and a
size
data member, After listing the data
elds, you may use
...
to indiate the rest of the body of this lass, exept for the following
whih must be implemented:
(a) Implement a zero parameter onstrutor.
(b) Implement
add
. Y
ou must expand the array as appropriate.
1

Partial preview of the text

Download Quiz Questions on Java Lists and ArrayLists - Prof. Mark Weiss and more Quizzes Data Structures and Algorithms in PDF only on Docsity!

Quiz #1B

Name:

READ THE QUESTIONS CAREFULLY!!! DO NOT WASTE TIME DOING MORE THAN IS ASKED FOR. DO NOT IMPLEMENT METHODS UNLESS SPECI- FICIALLY REQUESTED. YOU DO NOT NEED TO COMMENT THE CODE. YOU MAY USE T INSTEAD OF AnyType. IN QUESTION 2 IF YOU INVOKE AN ARRAYLIST METHOD YOU MUST SHOW THE IMPLEMENTATION OF THE METHOD.

  1. Write an interfa e op3530.List with the publi metho ds b elow. (This is a di erent inter- fa e than what you wrote for program 1, but the prin iples are identi al.) List is the name of the generi interfa e that stores identi ally typ ed items and has the following fun tionality:

 Three a essors: ontains returns true if a sp e i ed ob je t is found in the set; returns false otherwise. isEmpty, tests if the List is empty; and size returns the numb er of elements urrently stored in the List ontainer.  Two mutators: One makes the List empty; the other (add) inserts a new item.

  1. Provide a generi lass op3530.ArrayList that implements the List interfa e. Represent the ArrayList internally as a primitive array, and a size data memb er, After listing the data elds, you may use ... to indi ate the rest of the b o dy of this lass, ex ept for the following whi h must b e implemented:

(a) Implement a zero parameter onstru tor. (b) Implement add. You must expand the array as appropriate.