Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Not sure why no one answer the question whenever i have some question part 1 is what is going to happen is after you remove

Not sure why no one answer the question whenever i have some question part 1 is what is going to happen is after you remove all the occurance the out come it going to be "GOOD" that is what we need to get for i am having problem getting that would you pls help me thanks

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 aBag = new LinkedBag(); 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 */ public interface StackInterface { /** Adds a new entry to the top of this stack. @param newEntry An object to be added to the stack. */ public void push(T newEntry); /** Removes and returns this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty before the operation. */ public T pop(); /** Retrieves this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty. */ public T peek(); /** Detects whether this stack is empty. @return True if the stack is empty. */ public boolean isEmpty(); /** Removes all entries from this stack. */ public void clear(); } // end StackInterface ============================================================================================================================= package asmt02Part04; import java.util.Random; /** * * @author JavaF */ public class BlurbGenerator { private final Random gen; /** * Instantiates a random number generator needed for blurb creation. */ public BlurbGenerator() { } /** * Generates and returns a random Blurb. A Blurb is a Whoozit followed by * one or more Whatzits. * @return */ public String makeBlurb() { } /** * Generates a random Whoozit. A Whoozit is the character 'x' followed by * zero or more 'y's. */ private String makeWhoozit() { } /** * Recursively generates a string of zero or more 'y's. */ private String makeYString() { } /** * Recursively generates a string of one or more Whatzits. */ private String makeMultiWhatzits() { } /** * Generates a random Whatzit. A Whatzit is a 'q' followed by either a 'z' * or a 'd', followed by a Whoozit. */ private String makeWhatzit() { } } ========================================================================================================================= File 2 package asmt02Part04; import java.util.Scanner; public class Blurbs { /** * Generates a series of Blurbs (a word in an alien language). * * @param args */ public static void main(String args[]) { BlurbGenerator blurbMaker = new BlurbGenerator(); Scanner scan = new Scanner(System.in); System.out.println("How many blurbs would you like? "); int numBlurbs = scan.nextInt(); for (int i = 1; i 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 with AI-Powered 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

Students also viewed these Databases questions