Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to you write the code to find output Please help me Exercise 1: What is the output of the following code snippet? BagInterface

image text in transcribed

I want to you write the code to find output Please help me

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()); 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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

Compute io (t) in the op amp circuit in Fig. vs = 4cos104tV. 100 k

Answered: 1 week ago

Question

What should be included in a code of ethics?

Answered: 1 week ago