True/False (10)
1. An abstract data type is not necessarily a collection.
Answer: true
2. A collection is not necessarily an abstract data type.
Answer: false
3. Entries of a bag can belong to classes related by inheritance.
Answer: true
4. Entries of a bag may belong to different classes because items are unordered.
Answer: false
5. All entries of a bag must have the same data type or a subtype of that data type.
Answer: true
6. By declaring a data type to be a BagInterface, we can replace the bag class with another class
that implements the BagInterface.
Answer: true
7. A method can change the state of an object passed to it as an argument.
Answer: true
8. A set is a special kind of bag.
Answer: true
9. You cannot determine the exact number of times a particular item appears in a bag because it is
unordered.
Answer: false
10. Code written with respect to an interface makes it difficult to replace one implementation of a
bag with another.
Answer: false
SCHOLARVAULT
,Short #mgAnswer #mg(5)
1. Explain #mgthe #mgrationale #mgfor #mgreturning #mga #mgBoolean #mgvalue #mgfrom #mgthe #mg add #mgbag #mgoperation.
Answer: # m g A #mgclient #mgshould #mgknow #mgwhat #mghappened. #mgA #mgBoolean #mgvalue #mgindicates #mgtrue
#mgfor #mgsuccess #mgor #mgfalse #mgfor #mga #mgfailed #mgoperation.
2. Explain #mgwhy #mgwriting #mga #mgtest #mgprogram #mgbefore #mgimplementing #mga #mgclass #mgis #mga #mggood #mgidea.
Answer: # m g It #mghelps #mgyou #mgunderstand #mgthe #mgspecifications #mgbefore #mgcommitting #mgto #mgyour #mgdesign
#mgand #mgimplementation.
3. Explain #mgwhy #mgthe #mgset #mgADT #mgdoes #mgnot #mgneed #mga #mggetFrequencyOf #mgoperation.
Answer: # m g Because #mgsets #mgdo #mgnot #mgcontain #mgduplicate #mgitems, #mgonly #mga #mg0 #mgfor #mgabsence
#mgor #mg1 #mgfor #mgpresence #mgof #mgan #mgitem #mgwould #mgbe #mgreturned. #mgUsing #mga #mgcontains #mgmethod
#mgis #mga #mgbetter #mgdesign.
4. What #mgis #mgthe #mgdesign #mgrationale #mgfor #mgproviding #mga #mgtoArray #mgmethod #mginstead #mgof #mga
#mg displayBag #mgmethod? #mgAnswer: # m g The #mguser/client #mgis #mgfree #mgto #mgdisplay #mgany #mgor #mgall
of #mgthe #mgitems #mgin #mgany #mgway #mgdesired.
#mg
5. Explain #mgwhy #mgnull #mgis #mga #mgpotential #mgreturn #mgvalue #mgfor #mgthe #mgremove #mgoperation.
Answer: # m g It #mgis #mga #mgvalue #mgthat #mgcannot #mgbe #mgin #mgthe #mgbag #mgand #mgtherefore #mgsignals #mga
#mgproblem #mgif, #mgfor #mgexample, #mga #mgclient #mgtries #mgto #mgremove #mgan #mgentry #mgfrom #mgan #mgempty
#mgbag.
Multiple #mgChoice #mg(30) #mgWARNING: #mgCORRECT #mgANSWERS #mgARE #mgIN #mgTHE #mgSAME #mgPOSITION
#mgAND #mgTAGGED #mgWITH #mg**. #mgYOU #mgSHOULD #mgRANDOMIZE #mgTHE #mgLOCATION #mgOF #mgTHE
#mgCORRECT #mgANSWERS #mgIN #mgYOUR #mgEXAM.
1. A #mglanguage-independent #mgspecification #mgfor #mga #mggroup #mgof #mgvalues #mgand #mgoperations #mgon
#mgthose #mgvalues #mgis #mgcalled #mga/an:
a. abstract #mgdata #mgtype # m g **
b. data #mgstructure
c. collection
d. primitive
2. An #mgimplementation #mgof #mgan #mgADT #mgwith #mga #mgprogramming #mglanguage #mgis #mgcalled #mga/an:
a. data #mgstructure #mg**
b. abstract #mgdata #mgtype
c. collection
d. primitive
SCHOLARVAULT
,3. An #mgobject #mgthat #mggroups #mgother #mgobjects #mgand #mgprovides #mgservices #mgto #mgits #mgclients #mgis #mgcalled
#mga/an:
a. collection #mg**
SCHOLARVAULT
, b. abstract #mgdata #mgtype
c. data #mgstructure
d. primitive
4. Which #mgof #mgthe #mgfollowing #mgis #mgnot #mgtrue #mgwith #mgregard #mgto #mgbags?
a. objects #mgare #mgin #mga #mgspecific #mgorder #mg**
b. can #mgcontain #mgduplicate #mgitems
c. is #mgan #mgabstract #mgdata #mgtype
d. is #mga #mgkind #mgof #mgcollection #mgin #mgJava
5. Which #mgbehavior #mgis #mgnot #mgrepresented #mgin #mga #mgbag?
a. reorder #mgthe #mgbag #mg**
b. report #mgthe #mgnumber #mgof #mgitems #mgin #mgthe #mgbag
c. report #mgif #mgthe #mgbag #mgis #mgempty
d. add #mgan #mgitem #mgto #mgthe #mgbag
6. Which #mgmethod #mgreturns #mga #mgcount #mgof #mgthe #mgcurrent #mgnumber #mgof #mgitems #mgin #mga #mgbag?
a. getCurrentSize() #mg**
b. getSize()
c. size()
d. currentSize()
7. Why #mgwould #mgthe #mgadd #mgmethod #mgreturn #mgfalse?
a. when #mgthe #mgaddition #mgof #mga #mgnew #mgitem #mgwas #mgnot #mgsuccessful #mg**
b. when #mgthere #mgwas #mga #mgduplicate #mgof #mgthe #mgentry #mgalready #mgin #mgthe #mgbag
c. when #mgthere #mgwas #mgnot #mga #mgduplicate #mgof #mgthe #mgentry #mgalready #mgin #mgthe #mgbag
d. when #mgaddition #mgof #mga #mgnew #mgitem #mgwas #mgsuccessful
8. Which #mgmethod #mgremoves #mgall #mgentries #mgof #mga #mgbag?
a. clear() #mg**
b. remove()
c. delete()
d. empty()
9. Which #mgmethod #mgremoves #mgone #mgunspecified #mgentry #mgfrom #mga #mgbag #mgif #mgpossible?
a. remove() #mg**
b. clear #mg()
c. delete()
d. empty()
10. Which #mgmethod #mgremoves #mgone #mgoccurrence #mgof #mga #mgparticular #mgentry #mgfrom #mga #mgbag #mgif
#mgpossible?
a. remove(anItem) #mg**
SCHOLARVAULT