Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

e Exercise 1: What is the output of the following code snippet? BagInterface myBag = new ArrayBag(10); myBag.add(A); myBag.add(B); myBag.add(C); myBag.add(D); myBag.add(E); myBag.add(F); myBag.add(G); myBag.add(A);

image text in transcribed

e Exercise 1: What is the output of the following code snippet? BagInterface myBag = new ArrayBag(10); myBag.add("A"); myBag.add("B"); myBag.add("C"); myBag.add("D"); myBag.add("E"); myBag.add("F"); myBag.add("G"); myBag.add("A"); myBag.add("B"); myBag.add("C"); myBag.add("D"); myBag.add("E"); System.out.println( myBag.add("A")?"Item added":"item is not added-Error"); System.out.println( myBag.add("B")?"Item added":"item is not added-Error"); System.out.println( myBag.remove()); System.out.println( myBag.remove("B")?"item removed":"item doesn't exist"); System.out.println( myBag.remove("B")?"item removed":"item doesn't exist"); System.out.println( myBag.remove("B")); System.out.println("Do I have A? "+myBag.contains("A")); System.out.println("Do I have B? "+myBag.contains("B")); System.out.println("How many A do I have in the bag? "+myBag.getFrequencyOf("A")); System.out.println("How many B do I have in the bag? "+myBag.getFrequencyOf("B")); System.out.println("How many Items do Ihave in the bag?" + myBag.getCurrentSize()); while(!myBag.isEmpty) System.out.print myBag.remove(); System.out.println("How many Items do Ihave in the bag? "+myBag.getCurrentSize())

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago