Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is in java and please explain how you get to the final result and how expla

ID: 3788006 • Letter: T

Question

This is in java and please explain how you get to the final result and how explain everything works

Assume statesBag is a type of BagInterface<String>. What will print after the following statements are executed:

System.out.println(statesBag.isEmpty());

statesBag.add("alaska");

statesBag.add("california");

statesBag.add("delaware");

statesBag.add("california");

statesBag.add("georgia");

statesBag.add("delaware");

statesBag.add("delaware");

statesBag.add("iowa");

System.out.println(statesBag.isEmpty());

System.out.println(statesBag.getCurrentSize());

System.out.println(statesBag.remove("california"));

System.out.println(statesBag.getCurrentSize());

System.out.println(statesBag.remove("california"));

System.out.println(statesBag.remove("california"));

System.out.println(statesBag.remove("hawaii"));

System.out.println(statesBag.getCurrentSize());

System.out.println(statesBag.getFrequencyOf("delaware"));

System.out.println(statesBag.contains("hawaii"));

System.out.println(statesBag.getFrequencyOf("hawaii"));

statesBag.clear();

System.out.println(statesBag.getCurrentSize());

Explanation / Answer

Please find my answeres inline to the statements below.

In this first statement, statesBag is validated if it is really empty or containing any values. If it is not containing any value, it returns false and prints false in
standard out.

This statement will add a state called "alaska" to the Bag.

This statement will add a state called "california" to the Bag.

This statement will add a state called "delaware" to the Bag.

This statement will add a state called "california" to the Bag.

This statement will add a state called "georgia" to the Bag.

This statement will add a state called "delaware" to the Bag.

This statement will add a state called "delaware" to the Bag.

This statement will add a state called "iowa" to the Bag.

This statement prints as false in standard out as the elements are added to the Bag.

This statement prints "8" as the current size. Because, in this case, we have inserted delaware 3 times which means we have inserted three different elements.
Like wise the same way Bag treats california element as well. it make two insertions.

This statement removes california from the Bag implementation.

This statement prints the current size of the BagInterface statesBag as 7. As california has been removed once from the statesBag which has two insertions for california.

This statement removes california from the Bag implementation once more.

This statement throws an error as the statesBag does not contain california any more.

This statement throws an error as the statesBag does not contain hawaii.

This statement prints the current size of the BagInterface statesBag as 6.

If the getFrequencyOf() method is implemented as Collections.frequency(Object, Key), then it shall return the number of times that "delaware" is inserted into the Bag statesBag.

This statement prints as false as hawaii was never inserted into the Bag statesBag.

This statement should print "0". as hawaii was never inserted into the Bag.

This statement shall clear all the elements in the statesBag.

This statement should print "0" as statesBag is completely cleared.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote