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:
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started