Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this question is pretty clear i guess i am not sure what do you write on the comment below it said define the metheod removeAllOcurrence

this question is pretty clear i guess i am not sure what do you write on the comment below it said define the metheod removeAllOcurrence for the class LinkedBag then they give you how the out put looks like if you can;t would you please transfer

image text in transcribedimage text in transcribed

package asmt02Part01; /** * An interface that describes the operations of a bag of objects. * * **************************** PLEASE DO NOT CHANGE THIS FILE *********** * * @author Frank M. Carrano * @author Timothy M. Henry * @param */ public interface BagInterface { /** * Gets the current number of entries in this bag. * * @return The integer number of entries currently in the bag. */ public int getCurrentSize(); /** * Sees whether this bag is empty. * * @return True if the bag is empty, or false if not. */ public boolean isEmpty(); /** * Adds a new entry to this bag. * * @param newEntry The object to be added as a new entry. * @return True if the addition is successful, or false if not. */ public boolean add(T newEntry); /** * Removes all occurrences of the given entries * * @param entries */ public void removeAllOccurences(T[][] entries); /** * Retrieves all entries that are in this bag. * * @return A newly allocated array of all the entries in the bag. Note: If * the bag is empty, the returned array is empty. */ public T[] toArray(); } // end BagInterface ======================================================================================== package asmt02Part01; import java.util.Arrays; /** * A class of bags whose entries are stored in a chain of linked nodes. The bag * is never full. * * @author Frank M. Carrano * @author Timothy M. Henry * @author (modifier) Duc Ta * @param */ public final class LinkedBag implements BagInterface { private Node firstNode; // Reference to first node private int numberOfEntries; public LinkedBag() { firstNode = null; numberOfEntries = 0; } // end default constructor /** * Gets the number of entries currently in this bag. * * @return The integer number of entries currently in this bag. */ @Override public int getCurrentSize() { return numberOfEntries; } // end getCurrentSize /** * Sees whether this bag is empty. * * @return True if this bag is empty, or false if not. */ @Override public boolean isEmpty() { return numberOfEntries == 0; } // end isEmpty /** * Adds a new entry to this bag. * * @param newEntry The object to be added as a new entry * @return True if the addition is successful, or false if not. */ @Override public boolean add(T newEntry) // OutOfMemoryError possible { // Add to beginning of chain: Node newNode = new Node(newEntry); newNode.next = firstNode; // Make new node reference rest of chain // (firstNode is null if chain is empty) firstNode = newNode; // New node is at beginning of chain numberOfEntries++; return true; } // end add /** * Retrieves all entries that are in this bag. * * @return A newly allocated array of all the entries in this bag. */ @Override public T[] toArray() { // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") T[] result = (T[]) new Object[numberOfEntries]; // Unchecked cast int index = 0; Node currentNode = firstNode; while ((index (); displayBag(aBag); // Adding strings System.out.println("[+] Creating bag items..."); String[] contentsOfBag = {"A", " ", " ", "G", "Bb", "A", " ", "u", "n", "o", "A", "o", "d", "Bb", "A", "A", "l", "l"}; testAdd(aBag, contentsOfBag); // Removing all occurence of the given entries from a bag System.out.println("[+] Creating a 2D testArray... \t"); String[][] testArray = { {"A", "A", "A", "A", "A", "A"}, {"B", "Bb", "Bb"}, {"C", " "}, {"n", "u", "l", "l"} }; for (String[] row : testArray) { System.out.print("\t\t\t\t\t"); for (String col : row) { System.out.print(col + " "); } System.out.println(""); } System.out.println(""); System.out.println("[+] Removing testArray items from the bag..."); aBag.removeAllOccurences(testArray); displayBag(aBag); } // end main // Tests the method add. private static void testAdd(BagInterface aBag, String[] content) { System.out.print("[+] Adding the bag items to the bag: \t"); for (String content1 : content) { aBag.add(content1); System.out.print(content1 + " "); } // end for System.out.println(); displayBag(aBag); } // end testAdd // Tests the method toArray while displaying the bag. private static void displayBag(BagInterface aBag) { System.out.print("- The bag now contains " + aBag.getCurrentSize() + " string(s): \t"); Object[] bagArray = aBag.toArray(); for (Object bagArray1 : bagArray) { System.out.print(bagArray1 + " "); } // end for System.out.println(" "); } // end displayBag } // end LinkedBagDemo ================================================================================================================================================ package asmt02Part03; import java.util.Stack; /** * A class of stacks. */ public class OurStack implements StackInterface { Stack theStack; public OurStack() { } // end default constructor public void push(T newEntry) { } // end push public T peek() { } // end peek public T pop() { } // end pop public boolean isEmpty() { } // end isEmpty public void clear() { } // end clear } // end OurStack =================================================================================================================================== File 2 package asmt02Part03; import java.util.Scanner; /** * * A class that determines whether or not a string is a palindrome; * that is, a string that's able to be spelled the same way from * left to right as it is right to left, ignoring punctuation, * spaces, and case. * */ public class PalindromeChecker { /** * * Tests whether a string is a palidrome, * ignoring punctuation, spaces, and case. * * @param aString A string. * @return * * */ public static boolean isPalindrome(String aString) { StringBuilder tempString = new StringBuilder(aString); // // // // // // // // // while (!done && (continuingIndex PART1- The Bag, 20 points Define the method removeAlloccurrences for the class LinkedBag that removes all occurrences of the given entries from a bag. Your program's output must be identical to this output: Creating an empty bag - The bag now contains 0 string(3 t] creating bag items + Adding the bag items to the bag: -The bag now contains 18 string (s): llA A Bb d oAonuA Bb G A. Creating a 2D testArray... B Bb Bb n ul 1 + Removing testArray items trom the bag. . - The bag now contains 4 string (5) G o o PART 2 - The Efficiency of Algorithms, 10 points 1. Show how you count the number of operations (not only 2. Consider the following two loops, 4 points basic operations) required by the algorithm, 4 points: // Loop A for (1 = 1; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

4. When is it appropriate to show grace toward others?

Answered: 1 week ago