Question: 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

 I want to you write the code to find output Please

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!