Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write method requirements: [15 points] countVowelsAndConsonants() in your MyArrayBag class that accomplishes the following set of Create three bags that can hold strings. One

Write method count VowelsAnd Consonants() in your MyArrayBag class that accomplishes the following set of Follow the steps given below to create a Bag that uses an Array implementation for the ADT Bag [35 pts] (a) In another example as shown below, WWFABA is not a subsequence of ZWABCEFAABX, for the following 2 reasons. Longest Common Subsequence Suppose we want to find the longest sequence of letters that is common between two E. Modify your algorithm from before such that it will end early if there is a bag overflow [5 points] B. Examine your sample simulation, and give an algorithm for what to do during a single step. [5 points] C. A. Using the above as a sample simulation model, complete the seven steps below by putting in the numbers in We want to visualize the process of the simulation as a series of steps and from that determine an algorithm.

Write method requirements: [15 points] countVowelsAndConsonants() in your MyArrayBag class that accomplishes the following set of Create three bags that can hold strings. One bag is named letters and contains several one-letter strings. Another bag is named vowels and contains five strings, one for each vowel. The third bag is empty and is named consonants. Create and populate the 3 bags as part of an initialization process One at a time, remove a string from letters. Check whether the string is in the bag vowels. If it is, discard the string. Otherwise, place it into the bag consonants. After you have checked all the strings in letters, report the number of consonants in the bag consonants and the number of times each consonant appears in the bag Be sure to write code that will allow grader to test this functionality. Provide instructions for the grader on how you'd want this to be tested. Follow the steps given below to create a Bag that uses an Array implementation for the ADT Bag [35 pts] (a) Create interface MyArrayBagInterface as discussed in class and outlined in Listing 1-1 of the Textbook (b) Create MyArrayBag class that implements the above interface. Your class should limit the maximum number of items you can add to the bag to 10 (c) Create all required methods for MyArrayBag class, as mandated by the interface (d) In addition, write a 1-argument method findAndRemove such that it: removes all occurrences of an item(argument string) from a bag returns the count of the items found - (e) Create a ArrayBag Test class, that will be used for testing your bag. In the main method for this class, write code to test your MyArrayBag class as follows: create a new bag called myGroceryBag add 5 strings each of which represents the name of the grocery item you are adding test this bag object using each interface method implemented in the bag class test count() method, by adding grocery items strings, repeating some items so as to create duplicates/triplicates/quadruplicates etc. For example, your bag could be like ["Shampoo", "Soup", "Milk", "Shampoo", "Soup", "Milk", "Milk", "Milk"]. Then, use the count() method to list each items and its count alongside item name 4. Union function We know the union of two collections consists of their contents combined into a new collection. Add a method union() to the interface Baglnterface for the ADT bag that returns as a new bag the union of the bag receiving the call to the method and the bag that is the method's one argument. Include sufficient comments to fully specify the method. [5 points] Finally implement this method in the MyArrayBag class above. Add code in the class to test this functionality. [15 points] In another example as shown below, WWFABA is not a subsequence of ZWABCEFAABX, for the following 2 reasons. (a) We can only match up one character with one character so the subsequence check fails due to an excess of W's (b) While ABA is a subsequence of ZWABCEFAABX, FABA is not. Z W A B C E F A A B X WWFA BA Write an algorithm below for a method that given two strings (test, against) will return true if the first is a subsequence of the second. (Hint: We will accept an empty string as a subsequence of any other string.) [10 points] Longest Common Subsequence Suppose we want to find the longest sequence of letters that is common between two strings. For one string to be a subsequence of the other, all letters in the first string must match up uniquely with a letter in the second string. The matches have to be the same order, but they need not be consecutive. For example, as shown below, WBCAX is a subsequence of ZWABCEFAABX as we can see from the matching. Z WA B CE FA A B X W BCA X Conversely, WBAFX is not a subsequence of ZWABCEFAABX since there is no way to match up the letters in the correct order. Z W A B C E F A A B X W BAF X E. Modify your algorithm from before such that it will end early if there is a bag overflow [5 points] B. Examine your sample simulation, and give an algorithm for what to do during a single step. [5 points] C. Given your previous algorithm, come up with an algorithm that performs the simulation. Don't forget to do initialization and report the result. [5 points] Hydra: As discussed in class, their may be instances where the add() method may not succeed. For example, if there is not enough space in the bag to add the item, the add method may/will return false and the item will not be added into the bag. Such a situation will obviously have an effect on our simulation. Every time we add an item into a bag, we need to examine the returned value. If false is returned, the simulation will need to be stopped and you should report the failure of add() method. D. Modify your algorithm from before so that it is a method which returns true if the step was successful and false otherwise. [5 points] A. Using the above as a sample simulation model, complete the seven steps below by putting in the numbers in the simulation for a hydra starting with a single head of size 3. [5 points] headBag :3 workBag headBag workBag cut cut headBag workBag headBag workBag cut cut cut headBag workBag headBag workBag cut cut headBag workBag & headBag workBag We want to visualize the process of the simulation as a series of steps and from that determine an algorithm. For example, if we start with one head of size 5, one cut results in the following transition. headBag 5 workBag cut head Bag workBag chop

Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

It would be beneficial to provide more context or specific details about the query or objective you are attempting to achieve in order to address the issue It is challenging to offer a service that is ... 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

Programming Logic & Design Comprehensive

Authors: Joyce Farrell

9th edition

978-1337102070

More Books

Students also viewed these Programming questions

Question

Recognize the power of service guarantees.

Answered: 1 week ago

Question

Example: Solve the systems x - 2 y = 0 2 x + 2 y = 0

Answered: 1 week ago