Concept explainers
Write a method in your ArrayUtilities class that meets the following requirements: - It should be named "counts".]
- It should declare a parameter for an int array. You may assume that the array will contain only non-negative values.
- It should return an int array where the value at each index is the count of how many times the index appears in the original array
. For example, if the original array contained the value 10 3 times, then the value at index 10 in the count array should be 3.
- Hint: the size of the array is determined by the maximum value in the original array. If the original array is empty, the count array should also be empty.
A more detailed example:
Given the int array [1, 2, 3, 4, 4, 1, 1, 2, 0, 6], your function would return the array [1, 3, 2, 1, 2, 0, 1]. The value at each index indicates how many times the index appears in the original array.
The value at index 0 is 1 because 0 appears 1 time in the original array.
The value at index 1 is 3 because 1 appears 3 times in the original array.
The value at index 5 is 0 because 5 does not appear in the original array. And so on. Modify your main to test your method with at least one unsorted array.
Output Screenshot:
Step by stepSolved in 2 steps with 2 images
- Write the definition of a method reverse, whose parameter is an array of chars. The method reverses the elements of the array. The method does not return a value.arrow_forward5. Complete the class code below and include a method named partition which takes an integer array and a partition integer as parameters and then partitions the original array into two new arrays where elements of the first array are all less than or equal to the partition integer and the second array are all greater than the partition integer. The method should print the original array, followed by the lower partition and finally the upper partition. Nothing should be returned by the method. For example, given int[ ] arr = {1, 45, 16, 7, 39, 6, 5, 11, 72, 31, 15} a method call to partition(arr, 11) should output: %3D [1, 45, 16, 7, 39, 6, 5, 11, 72, 31, 15] [1, 5, 6, 7, 11] [15, 16, 31, 39, 45, 72] public class Partition { public static void main(String[] args) { int[] arrayToPartition = {1, 45, 16, 7, 39, 6, 5, 11, 72, 31, 15}; %3D int partitionNumber = 11; partition(arrayToPartition, partitionNumber); } /l your method code here } // end of Partition classarrow_forwardDefine a class called Book. This class should store attributes such as the title, ISBN number, author, edition, publisher, and year of publication. Provide get/set methods in this class to access these attributes. Define a class called Bookshelf, which contains the main method. This class should create a few book objects with distinct names and store them in an ArrayList. This class should then list the names of all books in the ArrayList. Enhance the program by providing a sort function, which will sort the books in ascending order of their year of publication. Create a few more Bookobjects with the same names but with different edition numbers, ISBNs, and years of publication. Add these new Book objects to the ArrayList, and display the book list sorted by book name; for duplicate books of the same name, sort the list by year of publication. (Hint: You will need to define a comparator class that takes two Book objects as parameters of the compareTo This method should do a two-step…arrow_forward
- Problem: Write a method that will determine whether a given value can be made given an array of coin values. For example, each value in the array represents a coin with that value. An array with [1, 2, 3] represents 3 coins with the values, 1, 2, and 3. Determine whether or not these values can be used to make a desired value. The coins in the array are infinite and can only be used as many times as needed. Return true if the value can be made and false otherwise. Dynamic Programming would be handy for this problem. Data: An array containing 0 or more coin values and an amount. Output: Return true or false. Sample Data ( 1, 2, 3, 12, 5 ), 3 ( 4, 15, 16, 17, 1 ), 21 ( 1 ), 5 ( 3 ), 7 Sample Output true true true falsearrow_forwardHow is this program written in java?arrow_forwardIn Java Write an application that inputs five numbers, each between 10 and 100, inclusive. As each number is read, display it only if it’s not a duplicate of a number already read. Provide for the “worst case,” in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user enters each new value. Rough output in screenshotarrow_forward
- Create a class called CustomerListerwith a mainmethod that instantiates an array of Stringobjects called customerName. The array should have room for five Stringobjects. Use an initializer list to put the following names into the array:Cathy Ben Jorge Wanda FreddieUse newto create a second doublearray called customerBalancein the mainmethod. Allow room for five customer balances, each stored as a double.In the loop that prints each customer name, add some code to prompt the user to enter a balance for that customer. Read the keyboard input with a Scannerobject. Use the following balances for the input:100.00234.562.4932.32400.00After all the balances have been entered, print out each customer and his/her balance.arrow_forwardA method named getUserStringsAndPopulate Array(). This method should keep prompting the user to enter as many strings as the user wants. The user should be able to stop entering strings by entering EXIT. This method should take the strings entered by the user and populate a one-dimensional array of strings with the user input. The string EXIT should NOT be added to the array because it is a special flag that will tell the method to stop prompting the user to enter more strings. This method should return the one-dimensional array of strings populated with user input and should not accept any arguments. 2.b) A method named searchArray() that would accept a one-dimensional array of strings and search the array for the string Winter. The search logic should NOT be case sensitive. If a match is found, this method should print the string in the array followed by a message like " --- Found a match!". Otherwise, the method should not print anything. This method should NOT return anything.…arrow_forwardThis code is for java see image thank youarrow_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