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...
-
Sir Isaac Newton measured sound speed by timing the difference between seeing a cannons puff of smoke and hearing its boom. If the cannon is on a mountain 5.2 miles away, estimate the air temperature...
-
Sentinel Industries has manufactured prefabricated houses for over 20 years. The houses are constructed in sections to be assembled on customers' lots. Sentinel expanded into the precut housing...
-
In low-speed external flow over a bluff object, vortices are shed from the object (as shown in Fig. P7.70). The frequency of vortex shedding, \(f \doteq 1 / \mathrm{T}\), depends on \(ho, \mu, V\),...
-
Here is a proposed income statement of a childrens clothing store: List and describe any shortcomings of this statement. Kids 2 Klad Statement of Profit and Loss, December 31, 20X1 Revenues: Sales...
-
Consider the following information: State of Economy Boom Good Poor Bust Probability of Rate of Return if State Occurs State of Economy Stock A Stock B Stock C .10 .30 .40 .20 .50 .15 .11 .09 .35...
-
Cesar Ablang is a product manager for a Malaysian firm. His product is made in batches of 2,500 units each. In past years, his product cost was $14.50 per unit, including $8 in variable costs. The...
-
Write the hypothesis(Geometric and AXIOM Systems). [12] If AB < CD then show that 2 AB < 2. CD.
-
Explain the distinct and complementary role(s) that equity, debt, mezzanine. When/where/how are various products used? How might they be combined? Why have private credit/debt funds grown in recent...
-
Use JavaScript to implement the Client-Side Encryption Tool Interface as shown in Figure 1. (2) Use a Crypto Library to implement AES-256 encryption on a secret message with a list of your accounts,...
-
Write out and solve the formula to value a bond. The bond's attributes are coupon rate of 3.75%, semi-annual interest payments, 3 years to maturity and the current return for 3 year paper is 2.875%
-
Nadal Athletic uses a periodic inventory system and has the following transactions related to its inventory for the month of August 2024: Date August 1 Transactions Beginning inventory Units 8 Unit...
-
Identify the tax issue(s) posed by the facts presented.problem Determine the possible tax consequences of each issue that you identify.problem Raquel is an employee of Jones Company and owns a 30%...
-
Critically discuss the needs of a person with depression in relation to and incorporating mental health promotion and behavior change needs. Your mental health promotion suggestions should be...
-
Heineken N.V., a global brewer based in the Netherlands, reports the following balance sheet accounts for the year ended December 31, 2016 (euros in millions). Prepare the balance sheet for this...
-
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...
-
Presented below is information for Bach Chocolatiers for the month of March 2025. Instructions a. Prepare an income statement. b. Prepare a comprehensive income statement. c. Compute the gross profit...
-
The trial balance columns of the worksheet for Barbosa Apparel at June 30, 2025, are as follows. Other data: Operating expenses incurred on account, but not yet recorded, total R$1,640. Instructions...
-
In 2025, Endeaver Cameras had net sales of 860,000 and cost of goods sold of 533,200. Operating expenses were 221,000, and interest expense was 7,000. Instructions a. Compute Endeavers gross profit....
Study smarter with the SolutionInn App