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 Java method that takes an array of type int and returns a boolean value. The method returns true if the number of positive elements in the parameter array is larger than the number of negative elements. The method returns false if any of the following conditions is satisfied: • The parameter array is of length of 0 or 1 • The number of positive elements of the parameter array is less than or equal to the number of negative elements • The number of positive elements or negative elements is equal to zero The method's header is as follows. public static boolean verify (int[] x) Sample run Result int[] x = (1, 2, 3}; verify(x); {5}; verify(x); int[] x = {1, 2, 3, -5, -1}; boolean b = verify(x); int[] x = new int[0]; verify(x); false boolean b = int[] x = boolean b = false true false boolean b = BIU A Paragraph +varrow_forwardWrite a method that takes two arrays as parameters. It should return a new array where each position has the sum of the two corresponding positions in the two incoming arrays. The returned array should be as long as the longer of the two passed in arrays.arrow_forwardFour integers are read from input and stored into the array arrayToModify. Write a static method resetFirstValue() that takes an integer array parameter and replaces the first element with 1. Ex: If the input is 55 45 70 65, then the output is: Original array: 55 45 70 65 Changed array: 1 45 70 65 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Scannerscnr=newScanner(System.in); finalintNUM_ELEM=4; int[] arrayToModify=newint[NUM_ELEM]; inti; intuserNum; for (i=0; i<arrayToModify.length; ++i) { arrayToModify[i] =scnr.nextInt(); } System.out.print("Original array: "); printArr(arrayToModify); resetFirstValue(arrayToModify); System.out.print("Changed array: "); printArr(arrayToModify); } }arrow_forward
- A method named findElement that takes a double number and an array of double numbers as parameters and returns an array that includes the indices of all the number occurrences in the array. For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2} are passed, the method must return the array {1, 4, 5}. If the passed number does not occur in the array, the method must return an array of zero elementsarrow_forwardWrite 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_forwardPlease help me solve this with java 1-method called printArray that takes an array of double values and prints the arrayelements on the same line with one space between each two elements, then prints a new line.2. A method called getRandomElement that takes an array of double numbers and returns a random element from the array.3. A method called shiftArray that takes a double value and an array of double values. The method must shift the array in its place to the right, and insert the double value at index 0. Note that this method must not create a new array, it must rotate the array in its place.For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is 3.3, after invoking the method the array must become:3.3, 6.5, 2.1, 5.8, 1.54. A method called occurrences that takes a double value and an array of doubles as parameters, and returns the number of occurrences of the double value in the array.For example, if the double number 4.1 and the array {1.5,…arrow_forward
- Develop a complete Java application. In the main method of the application, create a jagged 2D array of type int having six rows (i.e. an array having six arrays). The number of elements in a particular row must be equal to the corresponding digit of your own roll number. For example, if somebody's roll number is 141257, then the resultant array would look like: 3 4 6. 7 8. 9. 10 11 12 13 14 15 16 17 18 19 20 Next, you must use nested loops to initialize the elements of the 2D array with the value of a counter that is incremented by 1 during each iteration of the inner loop, as shown in the above example. Finally, use nested loops to display the values of all the elements stored in the array. Each row must be printed in a separate line. For example, following would be the output for the above array. 1 2345 6. 78 9 10 11 12 13 14 15 16 17 18 19 20arrow_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_forwardWrite 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_forward
- In 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_forwardWrite the method sum2D() which accepts a two dimensional integer array and returns the sum of all the elements of the array.arrow_forwardWrite a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. The array's size may differ from 4. new code can only be added between existing code. as seen in image.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