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 picture. A corner value will use only four values: itself and three neighbors. An edge value will use only six values: itself and five neighbors. But an interior value will use nine values: itself and eight neighbors. So you will need to treat the corners and edges separately from the other cells.
The weights to use are:
The element itself has the highest weight of 4, the horizontal and vertical neighbors have a weight of 2, and the diagonal neighbors have a weight of 1.
For example, suppose the values in picture are
and the new array is called result. In assigning weights, we will arbitrarily start with an element and consider neighbors in a clockwise direction. Thus, the interior value in result [1] [1] is equal to
To arrive at this equation, we started with the element at picture [1] [1] and then, beginning with the neighbor to the right, we considered neighbors in a clockwise direction. The corner value in result [0] [0] is equal to
Note that picture [0] [0] has fewer neighbors than an interior value such as picture [1] [1]. The same is true for an edge value such as picture [0] [1]. Thus, the edge value in result [0] [1] is equal to
The final array, result, 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
Starting Out with Java: Early Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Problem Solving with C++ (9th Edition)
Digital Fundamentals (11th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- Write a method that sums the areas of all thegeometric objects in an array. The method signature is:public static double sumArea(GeometricObject[] a)Write a test program that creates an array of four objects (two circles and tworectangles) and computes their total area using the sumArea method.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_forwardwrite java program for the above questionarrow_forward
- Image one is my file or you can create ur own file as long as it's similar to mine. image 2 is my program I want to write a 4th method(method 4) and the spec is: A method to count the occurrences of each value in an array takes one parameter, an array of integers returns an array containing the number of times each value occurs in the parameter array. Also should call method 3 from method 4Hint: The general idea of this method is using an array with length maxVal+1(maxVal should get from method 3 already) to save the occurrences of each number. For example, if number 44 occurs 3 times in the file, your array should have a value 3 stored at index 44.arrow_forwardJAVAWrite a program that searches person's name and display all matched name. For example, if a user inputs the letter "Davis", the program searches all name which includes "Davis" in an array. Then, display all matched names on the screen. You must declare a single dimensional array which has all people’s name. Use methods of string classarrow_forwardCreate a program that will encrypt letters and create a secret code. You will create an array of numbers from 0 - 25. use [i for i in range (26)] to create an array of numbers from 0 - 25. use random.shuffle to to shuffle the above array. This will be used for a new letter index order. For example: The first created array [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] gets shuffled to become[2, 14, 12, 20, 16, 5, 11, 1, 13, 17, 15, 21, 19, 10, 23, 22, 25, 3, 6, 7, 18, 4, 9, 24, 0, 8] This will be used as the new index for the encrypted alphabet. create an array of letters using list(string.ascii_lowercase), this requires importing the string module. This will create: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] Accept an input of a word. Using the above tables take each letter of the word and convert it to the encrypted letter. Print each…arrow_forward
- Write a program that prompts the user for an integer, then asks user to enter that many integer value. Store these values in an integer array and print the array. Reverse the array elements so that first element become the last element, the second element become the second to last element, and so on, with the old last element now first. Do not just reverse the order in which they are printed; actually, change the way they are stored in the array. Try not to create a second array; just rearrange the elements within the array you have. (Hints; Swap elements that need to change place.) When the elements have been reversed, Print the array again.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_forwardCreate an array of 10 integers. Fill the array by taking input from user. Now check whether the array is palindrome or not. You can use any loop. A palindrome is a word, number or phrase which reads the same backward as forward, for example 4257227524 is a palindrome.Required to answer. Multi Line Text.arrow_forward
- In Java Write a program that counts the number of occurrences of lowercase and uppercase vowels inentered lines of text. Use a two-dimensional array to store the vowel counts. The array’s firstcolumn holds the counts for the lowercase vowels, and the second column holds the counts forthe uppercase vowels.The user indicates the end of the input by pressing enter by itself. At that point, your programshould print, for each vowel, the total number of lowercase occurrences, the total number ofuppercase occurrences, and the total number of combined occurrences.Here are some implementation requirements:1. Use two separate files – one for a main driver method and one for a VowelCounter classthat keeps track of vowel counts.2. main – Repeatedly prompt the user to enter a line of text or press enter by itself to quit.Note that the stdIn.nextLine() method returns the empty string ("") if the user pressesenter by itself. For each entered line of text, call the processLine method. When the…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_forwardWrite a program that uses arrays to store the registration number of your total class.it then search the index of your registration number in the array.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