162k views
2 votes
JAVA QUESTION:

Write a program that has two parts:

Part 1 – Create a new array that will be able to hold 10 values of type double. Populate the array with 10 random values. Display the contents of the array in the original order with a label. Then, sort the array, and display the contents once again, this time in sorted order, with a label (refer to Sample Output). Use loops where appropriate.

Part 2 - Now, ask the user for five animals. Store the answers in a new String array. Then, display the animal names in alphabetical order, along with their vowel counts (just consider a,e,i,o,u as vowels for now). Additional requirements:

As part of your solution, you must create a static method called vowelCount that takes an animal name as a single String parameter. The method will return the number of vowels found in the String provided.

You must call this method from main to obtain the vowel counts you will display.

As usual, refer to the Sample Output to clarify the required output of your program.

Tip: You may use any of the String or array-related methods we have discussed in class.

Sample Output:

User Edgarian
by
7.8k points

1 Answer

5 votes

Final answer:

To fulfill the requirements of the program: create an array, populate it with random values, display the contents, sort the array, display the sorted contents, ask the user for animals, store them in a String array, sort the names alphabetically, and display the vowel counts.

Step-by-step explanation:

To write a program that fulfills the requirements of Part 1, you can create a new double array with a size of 10 and use a loop to populate it with random values. Then, you can use another loop to display the contents of the array before sorting it. After sorting, you can use a loop again to display the sorted contents. For Part 2, you can ask the user for five animals and store them in a new String array. You can then use an array-related method to sort the animal names alphabetically. To obtain the vowel counts, you should create a static method called vowelCount that takes an animal name as a parameter and returns the number of vowels found in the string. You can call this method from main to get the vowel counts which you will display.

User Vhd
by
8.1k points