
Write a static method named "mostVowels" that accepts two arrays of strings str1 and str2 as parameters and returns a new array str3 such that each element of str3 at each index i stores whichever string has greater number of vowels when comparing the elements at that same index i in arrays str1 and str2. If there is a tie, take the element from str1. You may create additional helper methods if desired.
For example, if a1 and a2 store the following elements:
String[] str1 = {"star", "pie", "jelly bean", "car"};
String[] str2 = {"cookie", "fig", "banana", "soda"};
Then your method should return the new array
{"cookie", "pie", "jelly bean", "soda"}
If the arrays str1 and str2 are not the same length, the result returned by your method should have as many elements as the smaller of the two arrays. For example, if str1 and str2 store the following elements:
String[] str1 = {"Splinter", "Leo", "April", "Don", "Raph"};
String[] str2 = {"Krang", "Shredder", "Bebop"};
Then your method should return the new array
{"Splinter", "Leo", "Bebop"}
Do not make any assumptions about the length of str1 or str2 or the length of the strings. You may assume that neither array is null and that no element of either array is null.
You may use the following code to test your program:
Expected output is listed to the right of the method calls.
import java.util.*;
public class MoreVowels {
public static void main(String[] args) {
String[] a1 = {"star", "pie", "jelly bean", "car"};
String[] a2 = {"cookie", "fig", "banana", "soda"};
String[] a3 = mostVowels(a1, a2); // [cookie, pie, jelly bean, soda]
System.out.println(Arrays.toString(a3));
String[] a4 = {"Splinter", "Leo", "April", "Don", "Raph"};
String[] a5 = {"Krang", "Shredder", "Bebop"};
String[] a6 = mostVowels (a4, a5); // [Splinter, Leo, Bebop]
System.out.println(Arrays.toString(a6));
}
// *** Your method code goes here ***
} // End of MoreVowels class

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- How do you do this? JAVAarrow_forwardWrite a public static method named allLessThanMean that will take an ArrayList<Integer> as an argument. This method will return an ArrayList<Integer>. When called and passed anArrayList, this method will return an ArrayList containing all the elements in the argument ArrayList that are less than the average of all the values in the argument ArrayList. The values in the returned ArrayList must be in the same order as they are in the argument ArrayList. Here are some examples: Example 1 Given: ArrayList<Integer> myList = new ArrayList<Integer>(); with these values {1, 2, 3, 4, 5}; allLessThanMean(myList) should return an ArrayList<Integer> with these values {1, 2} Example 2 Given: ArrayList<Integer> myList = new ArrayList<Integer>(); with these values {3, 7, 6, 2, 9, 0, 4, 8}; allLessThanMean(myList) should return an ArrayList<Integer> with these values {3, 2, 0, 4} Example 3 Given: ArrayList<Integer> myList = new…arrow_forwardUse the ArrayList class Add and remove objects from an ArrayList Protect from index errors when removing Practice with input loop Details: This homework is for you to get practice adding and removing objects from an ArrayList. The Voter class was used to create instances of Voters which held their name and a voter identification number as instance variables, and the number of instances created as a static variable. This was the class diagram: The constructor takes a string, passed to the parameter n, which is the name of the voter and which should be assigned to the name instance variable. Every time a new voter is created, the static variable nVoters should be incremented. Also, every time a new voter is created, a new voterID should be constructed by concatenating the string “HI” with the value of nVoters and the length of the name. For example, if the second voter is named “Clark Kent”, then the voterID should be “HI210” because 2 is the value of nVoters and 10 is the number…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





