Question
Below is the java program import java.util.*; public class HomeworkM3Driver { public static void main(String[] args) { System.out.println(******TESTING QUESTION: TESTING IF BAG IS A SET);
Below is the java program
import java.util.*;
public class HomeworkM3Driver {
public static void main(String[] args) {
System.out.println("******TESTING QUESTION: TESTING IF BAG IS A SET");
BagInterface
System.out.println("Bag is set? true: " + isSet(wordBag));
System.out.println("The contents of the bag should be (in ANY order- the order might not match): []");
System.out.println(Arrays.toString(wordBag.toArray()));
wordBag.add("hi");
System.out.println("Bag is set? true: " + isSet(wordBag));
System.out.println("The contents of the bag should be (in ANY order- the order might not match): [hi]");
System.out.println(Arrays.toString(wordBag.toArray()));
wordBag.add("HI");
wordBag.add("hello");
System.out.println("Bag is set? true: " + isSet(wordBag));
System.out.println("The contents of the bag should be (in ANY order- the order might not match): [hi, HI, hello]");
System.out.println(Arrays.toString(wordBag.toArray()));
wordBag.add("hi");
System.out.println("Bag is set? false: " + isSet(wordBag));
System.out.println("The contents of the bag should be (in ANY order- the order might not match): [hi, HI, hello, hi]");
System.out.println(Arrays.toString(wordBag.toArray()));
wordBag.clear();
wordBag.add("a");
wordBag.add("c");
wordBag.add("b");
wordBag.add("d");
wordBag.add("a");
System.out.println("Bag is set? false: " + isSet(wordBag));
System.out.println("The contents of the bag should be (in ANY order- the order might not match): [a, c, b, d, a]");
System.out.println(Arrays.toString(wordBag.toArray()));
System.out.println(" ******TESTING QUESTION: CREATING LIST OF WORDS THAT CONTAIN CHAR");
ListInterface
ListInterface
System.out.println("The contents of the list should be: []");
System.out.println(Arrays.toString(shortWordList.toArray()));
wordList.add("apple");
wordList.add("anna");
wordList.add("bob");
wordList.add("ANIMAL");
wordList.add("canal");
wordList.add("frog");
wordList.add("cat");
shortWordList = createWordListContainChar(wordList,'a');
System.out.println("The contents of the list should be (in THIS ORDER): [apple, anna, canal, cat]");
System.out.println(Arrays.toString(shortWordList.toArray()));
System.out.println("The original list should still contain (in THIS ORDER): [apple, anna, bob, ANIMAL, canal, frog, cat]");
System.out.println(Arrays.toString(wordList.toArray()));
System.out.println(" ******TESTING QUESTION: FINDING LAST POSITION");
List
itemList.add("adam");
itemList.add("frank");
itemList.add("betty");
itemList.add("sue");
itemList.add("sam");
itemList.add("frank");
itemList.add("sue");
itemList.add("terry");
itemList.add("adam");
itemList.add("frank");
System.out.println("The index should be: 9 " + lastPosition(itemList, "frank"));
System.out.println(" ******TESTING QUESTION: LIST COMPARISON");
ListInterface
List
numListB.add(1);
numListB.add(3);
numListB.add(1);
numListB.add(5);
numListB.add(7);
System.out.println("Equivalent should be: false " + equivalentLists(numListA, numListB));
numListA.add(1);
System.out.println("Equivalent should be: false " + equivalentLists(numListA, numListB));
numListA.add(3);
numListA.add(1);
numListA.add(5);
System.out.println("Equivalent should be: false " + equivalentLists(numListA, numListB));
numListA.add(7);
System.out.println("Equivalent should be: true " + equivalentLists(numListA, numListB));
numListA.add(8);
System.out.println("Equivalent should be: false " + equivalentLists(numListA, numListB));
numListB.add(8);
numListB.add(10);
System.out.println("Equivalent should be: false " + equivalentLists(numListA, numListB));
System.out.println(" ******TESTING EXTRA CREDIT QUESTION: MOVE THE MINIMUM TO THE FRONT");
List
prioritizeMinimumValue(numberList);
System.out.println("The list should contain: [] " + numberList);
numberList.add(4);
prioritizeMinimumValue(numberList);
System.out.println("The list should contain: [4] " + numberList);
numberList.add(3);
numberList.add(1);
numberList.add(5);
numberList.add(7);
prioritizeMinimumValue(numberList);
System.out.println("The list should contain: [1, 4, 3, 5, 7] " + numberList);
numberList.add(0);
prioritizeMinimumValue(numberList);
System.out.println("The list should contain: [0, 1, 4, 3, 5, 7] " + numberList);
}
public static boolean isSet(BagInterface
{
String[] words = wordBag.toArray();
for(int i = 0; i < wordBag.getCurrentSize(); i++)
{
if(wordBag.getFrequencyOf(words[i]) > 1)
{
return false;
}
}
return true;
}
public static ListInterface
{
ListInterface
for(int i = 0; i < wordList.getLength(); i++)
{
if(wordList.getEntry(i).indexOf(key) != -1)
{
output.add(wordList.getEntry(i));
}
}
return output;
}
public static int lastPosition(List
{
return -1;
}
public static boolean equivalentLists(ListInterface
{
if(numberListInterface.getLength() != numberList.size())
{
return false;
}
for(int i = 0; i < numberList.size(); i++)
{
if(numberListInterface.getEntry(i) != numberList.get(i))
{
return false;
}
}
return true;
}
public static void prioritizeMinimumValue(List
// return;
}
}
-------------------------------------------------------------------------------------------------------------------
A method to find the last position of an item in aList.
The method header is:
public static int lastPosition(List wordList, String targetWord)
Notes:
- If the itemappears more than once, return the position of thelastappearance.
- Decide what to do if the item is not on the list.
- The wordList parameter should be unchanged when the method completes.
- do not use the lastIndexOf method in the ArrayList class.
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