Write method requirements: [15 points] countVowelsAndConsonants() in your MyArrayBag class that accomplishes the following set of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
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 ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Affordable Beauty Supply produces inexpensive combs, brushes, and hair clips. As a way to minimize costs when sending out these small items, the company combines 10 to 12 different orders into one....
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Consider a corporate bond with a 10.5% coupon rate, paid semi-annually, $1000 par value and a current market price of $766.70. It matures in exactly 20 years. What is the yield to maturity (YTM) on...
-
Osborn, Inc., produces cell phone equipment. Amanda Westerly, Osborn's president, implemented a quality-improvement program that has now been in operation for 2 years. The cost report shown here has...
-
A process plant has two streams of hot fluid and two streams of cold fluid, as defined in Table P19.1. It is required to minimise the energy which must be transferred to hot and cold utilities by...
-
If the conditional statement is true, and the conclusion is false, what is a valid conclusion to the argument? Use the conditional statement, \(p ightarrow q\) : "If Phil Mickelson is 50 years old,...
-
Pine Knoll Wood Products Company prepared the following factory overhead cost budget for the Press Department for February 2008, during which it expected to require 10,000 hours of productive...
-
What is the current yield of a four-year semi-annual pay bond with a par value of $1,000 and a 4% coupon rate when the bond is currently priced at $932.35?
-
Candy Craze purchased and installed a machine on January 1, 2023, at a total cost of $296,800. Straight-line depreciation was taken each year for four years, based on the assumption of a seven-year...
-
Swola Company reports the following annual cost data for its single product. Normal production level75,000 unitsDirect materials$1.25 per unitDirect labor$2.50 per unitVariable overhead$3.75 per...
-
. In this question you will be asked to construct new kernels from existing kernels. Suppose K (x,z): R x Rd R and K (x,z): Rd x Rd R are both kernels, show the following functions are also kernels:...
-
(1.1) Determine whether the system QUESTION 1 x+y+x+y= 2e3t +y 3x-3y = et, is degenerate. In the degenerate case, decide whether it has no solution or infinitely many solutions. If it has no...
-
Have you ever been particularly impressed or unimpressed with the way a company handled its recruiting of you? If so, were there any spillover effects?
-
Mercury Incorporated purchased equipment in 2022 at a cost of $313,000. The equipment was expected to produce 310,000 units over the next five years and have a residual value of $34,000. The...
-
Julie Schnitzel-Andrews (Yes, owner of the Bier-Schnitzel-Lederhosen Emporium) is thrown up into the air by the reveling B-S-L-E Biergarten crowd while singing "These are a Few of My Favorite Biers"....
-
1.The Dunley Corp. plans to issue 5-year bonds. It believes the bonds will have a BBB rating. Suppose AAA bonds with the same maturity have a 4% yield. Assume the market risk premium is 5% and use...
-
In order to get an idea on current buying trends, a real estate agent collects data on 10 recent house sales in the area. Specifically, she notes the number of bedrooms in each house as follows: a....
-
When an array is passed to a method, it is _____. a. Passed by reference b. Passed by value c. Unnamed in the method d. Unalterable in the method
-
Which of the following is not an advantage of creating a class that inherits from another class? a. You make it easier for anyone who has used the original class to understand the new class. b. You...
-
a. The Downdog Yoga Studio offers five types of classes, as shown in Table 6-1. Design a program that accepts a number representing a class and then displays the name of the class. Class Number Class...
-
RJ Manufacturing is considering buying the mounting brackets it uses to make its fire extinguishers from an outside supplier. Currently, RJ Manufacturing makes the brackets in its own manufacturing...
-
Jumbo Chinese Restaurant operates a small laundry facility to launder the uniforms, tablecloths, and other linens used by its restaurant chain. Jumbos laundry operation occupies space in an...
-
Abraham Manufacturing produces 22,000 rubber engine mounts each year for use in its electric cart manufacturing plant. Abrahams engine mounts have an excellent reputation for strength and durability....
Study smarter with the SolutionInn App