Write a static method findFigure (picture, threshold), where picture is a two-dimensional array of double values. The method should return a new two-dimensional array whose elements are either 0.0 or 1.0. Each 1.0 in this new array indicates that the corresponding value in picture exceeds threshold times the average of all values in picture. Other elements in the new array are 0.0.
For example, if the values in picture are
the average value is 5 55 The resulting array for a threshold of 1 4 would be
and the resulting array for a threshold of 0 6 would be
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Introduction to Programming Using Visual Basic (10th Edition)
Modern Database Management
Digital Fundamentals (11th Edition)
Concepts Of Programming Languages
Artificial Intelligence: A Modern Approach
Web Development and Design Foundations with HTML5 (8th Edition)
- Write a method that takes a rectangular two-dimensional array of type int. The method returns true if the sum of the even elements of the parameter array are larger than the sum of the odd elements, otherwise the method returns false. public static boolean sum(int[]0 in) Taken array Result 1 -3 17 5 -2 30 true 1 3 -1 -1 -3 -4 7 -1 10 false -1 3 -4 15arrow_forwardI need to have a main method in a Tester class that will: Fill an array of type Vehicle[] of size NUM_VEHICLES with Vehicle objects. You need to generate a random number between 0 and 2. If the number is 0, add a Vehicle to the array. 1, add a Car, 2, add a Boat. The Vehicle/Car/Boat that you add must be initialized with a random efficiency between 0 and 100.0. Do this until you have added NUM_VEHICLES objects to the array How do I write it so that the array generates random numbers 0 through 2 (inclusive) and how would I then correlate those numbers to a different class object?arrow_forwardIn this lab assignment you need to implement the method named middleValue, in a program named ArrayOps.java. The method accepts an array of integer values as a parameter, and returns the value in the middle of the array. For instance, if an array contains five elements, then the third element would be the middle element to be returned. However, if the array contains six elements, both the third and fourth values could be considered to be the middle elements. In this case, only return the first middle value, namely, the third element of the array. Complete the method middleValue, and test the correctness of your method in main(). Particularly, you should create two arrays (arbitrary values), one array with odd length, and the other with even length, and print out the middle values of these two arrays.arrow_forward
- Write a program that creates a 2-D array initialized with test data . Use any primitive type of data EXCEPT int (Integer). The program should have all methods in the problem. getTotal - This method should accept a two-dimensional array as its argument and return the total of all the values in the array. getAverage - This method should accept a two-dimensional array as its argument and return the average of all the values in the array. getRowTotal. - This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. getColumnTotal - This method should accept a two-dimensional array as its First argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column.…arrow_forwardWrite a method with header static void DisplayIntArray(int[] numbers). The first argument is an array of ints. There is no return value. This method displays all the elements of the argument on a single line. Each item will occupy three columns.Call this method from main with a suitable argument. Write a method with header static int[] GenerateRandomIntArray(int numberOfItems, int largestValue). The first argument is an int indicating the number of elements that will be present in the return array. The second argument is an int representing the largest item in the array. The returned value is an array of integers. This method does the following: Declare and initialized a variable of type Random (Random generator = new Random();) Declare an array of type int (you may call it result) Allocate storage for the correct number of items Using your favorite looping statement, assign a random integer to each element of the array (result[i] = generator.Next(largestValue);) In your…arrow_forwardDefine an array to be a 121 array if all elements are either 1 or 2 and it begins with one or more 1s followed by a one or more 2s and then ends with the same number of 1s that it begins with. Write a method named is121Array that returns 1 if its array argument is a 121 array, otherwise, it returns 0. There is one additional requirement. You should return 0 as soon as it is known that the array is not a 121 array; continuing to analyze the array would be a waste of CPU cycles. If you are programming in Java or C#, the function signature isint is121Array(int[ ] a) If you are programming in C or C++, the function signature isint is121Array(int a[ ], int len) where len is the number of elements in the array a. Examples a is then function returns reason {1, 2, 1} 1 because the same number of 1s are at the beginning and end of the array and there is at least one 2 in between them. {1, 1, 2, 2, 2, 1, 1} 1 because the same number of 1s are at the beginning and end of…arrow_forward
- Write a static method blur(double[][]picture) that you could use on a part of a picture file to obscure a detail such as a person’s face or a license plate number. This method computes the weighted averages of the values in picture and returns them in a new two-dimensional array. To find a weighted average of a group of numbers, you count some of them more than others. Thus, you multiply each item by its weight, add these products together, and divide the result by the sum of the weights. For each element in picture, compute the weighted average of the element and its immediate neighbors. Store the result in a new two dimensional array in the same position that the element occupies in picture. This new array is the one the method returns. The neighbors of an element in picture can be above, below, to the left of, and to the right of it, either vertically, horizontally, or diagonally. So each weighted average in the new array will be a combination of up to nine values from the array…arrow_forwardCreate class IntegerSet. Each IntegerSet object can hold integers 0 though n, where n can be different for different sets. The set is represented by an array of booleans. Array element a[i] is true if integer i is in the set. Array element a[j] is false if integer j is not in the set. Provide the following methods. Constructor IntegerSet(int n) creates an object with an array of size n with all cells set to false. Method union(IntegerSet set) creates a set that is the set-theoretic union of two existing sets (i.e., an element of the new set’s array is set to true if that element is true in at least one of the existing sets – otherwise, the new set’s element is set to false). Method intersection(IntegerSet set) creates a set which is the set-theoretic intersection of two existing sets (i.e., an element of the new set’s array is set to false if that element is false in at least one of the existing sets – otherwise, the new set’s element is set to true). Method insertElement(int n)…arrow_forwardA school has five classes (called Class 1, Class 2 etc) and they are selling boxes of cookies for a fundraiser. Your program accepts input (class number followed by number of boxes sold)…there are ten lines of input. Method getInput will collect this input and load and return an array of length 5, so that the total number of boxes sold by Class 1 is in the first element, the total for Class 2 is in element 1 etc. Method printOutput then outputs the result. In java pleasearrow_forward
- Write a method that takes an array of type int and returns a double value. The method returns the average value of the negative elements of the taken array. Sample run int] in = {1, 5, 7, -1,0, 3, -15)}; double out = avgNegative(in); System.out.printIn("Result: "+ out); int] in {1,3, 3, 5, 15}; double out = avgNegative(in): System.out.printIn("Result: "+ out); Output Result: -8.0 Result: 0.0 Paragraph B I + v ofarrow_forwardThe editTemperatures() method takes in two parameters: integer array tempData and integer numMore. Complete editTemperatures() to create a new array called arrayCopy with the same elements as tempData, and the size increased by numMore. Ex: If the input is: 10 48 49 18 3 then the output is: 10 48 49 18 0 0 0 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Scannerscnr=newScanner(System.in); int[] degreesFahrenheit=newint[4]; intinput; inti; for (i=0; i<degreesFahrenheit.length; ++i) { degreesFahrenheit[i] =scnr.nextInt(); } // Read number of values to increase array size by input=scnr.nextInt(); degreesFahrenheit=editTemperatures(degreesFahrenheit, input); for (i=0; i<degreesFahrenheit.length; ++i) { System.out.print(degreesFahrenheit[i] +" "); } } }arrow_forward19. A two-dimensional array is frequently called a matrix and such a matrix is usually displayed in a row X col format. Write a method, which displays a 3 X 4 matrix to the monitor, in a format like: sample data: 10 11 12 13 14 15 16 17 18 19 20 21 Complete method displayMatrix below. // precondition: // postcondition: 11 mat is a non-empty 2D array of int values. displayMatrix displays the elements of 2D array mat in Row X Col format. public static void displayMatrix(int[][] mat)arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage