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

Need some help on these refresher questions. Thanks Edit: There are no other inf

ID: 3742558 • Letter: N

Question

Need some help on these refresher questions. Thanks

Edit:

There are no other info given about interfaces or classes. Just what is below.

Question 1: Bag Trace

statesBag is type BagInterface. What is printed when the following statements are run?

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

Question 2: ListInterface Trace

cityList is type ListInterface. What is printed when the following statements are run?

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

cityList.add("burbank");

cityList.add("carlsbad");

cityList.add("davis");

cityList.add("granada");

cityList.add("sacramento");

cityList.add(2, "hayward");

cityList.add("menlo park");

cityList.add(4, "napa");

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

System.out.println(cityList.getLength());

System.out.println(cityList.getEntry(2));

System.out.println(cityList.remove(2));

System.out.println(cityList.getEntry(2));

System.out.println(cityList.remove(1));

System.out.println(cityList.remove(2));

System.out.println(cityList.remove(3));

System.out.println(cityList.getLength());

System.out.println(cityList.replace(2, "oakland"));

System.out.println(cityList.getEntry(2));

System.out.println(cityList.getEntry(3));

cityList.clear();

System.out.println(cityList.getLength());

Question 3: List Trace

cityList is type List. What is printed when the following statements are run?

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

cityList.add("burbank");

cityList.add("carlsbad");

cityList.add("davis");

cityList.add("granada");

cityList.add("sacramento");

cityList.add(2, "hayward");

cityList.add("menlo park");

cityList.add(4, "napa");

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

System.out.println(cityList.size());

System.out.println(cityList.get(2));

System.out.println(cityList.remove(2));

System.out.println(cityList.get(2));

System.out.println(cityList.remove(1));

System.out.println(cityList.remove(2));

System.out.println(cityList.remove(3));

System.out.println(cityList.getLength());

System.out.println(cityList.set(2, "oakland"));

System.out.println(cityList.get(2));

System.out.println(cityList.get(3));

cityList.clear();

System.out.println(cityList.getLength());

Question 4: Using BagInterface as a Client- clear

Pretend that there is no clear() method in BagInterface. How can you use the other provided methods (from the client perspective) to accomplish what the clear method does? Do not use the toArray method.

Question 5: Using Bag Interface as a Client- getFrequencyOf

Pretend that there is no getFrequencyOf() method in BagInterface. How can you use the other provided methods (from the client perspective) to accomplish what this method does?

If you alter the bag, make sure you re-create or restore it (because the getFrequencyOf method does not alter the bag).  Do not use the toArray method.

Question 6: Using ListInterface as a Client- clear

Pretend that there is no clear() method in ListInterface. How can you use the other provided methods (from the client perspective) to accomplish what the clear method does? Do not use the toArray method.

Question 7: Using ListInterface as a Client- count frequency

Write code from the client level to count the frequency of an entry (i.e., the number of times the entry appears) in a ListInterface object. Do not use the toArray method.

Question 8: Using List as a Client- count frequency

Write code from the client level to count the frequency of an entry (i.e., the number of times the entry appears) in a List object.

Question 9: Bags vs Lists

What is one similarity and one difference between the general data structure of a bag and a list?

Question 10: List vs ListInterface

What is one similarity and one difference between the List interface and the ListInterface interface?

Question 11: Coding Comparable

Assume you have a Computer class described by String name and int memoryInKB. Have the Computer class implement the Comparable interface. Write the new class header and the compareTo method. Order computers based on name first and then memory.

Explanation / Answer

SOLUTION:-

(1):- Output:-

true

false

8

7

6

3

false

0

0

=============================================================================

(2):- Output:-

  true

false

8

  hayward

  davis

4

  oakland

  menlopark

0

=======================================================================

(3):- Output:-

true

false

8

  hayward

  davis

4

  oakland

  menlo park

0

========================================================================================

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