Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 7, Problem 21E

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:

Chapter 7, Problem 21E, Write a static method blur (double [] [] picture) that you could use on a part of a picture file to , example  1

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

Chapter 7, Problem 21E, Write a static method blur (double [] [] picture) that you could use on a part of a picture file to , example  2

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

4 ( 3.3 ) + 2 ( 4.4 ) + 1 ( 2.1 ) + 2 ( 4.5 ) + 1 ( 1.1 ) + 2 ( 1.7 ) + 1 ( 1.2 ) + 2 ( 1.3 ) + 1 ( 4.5 ) 4 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1

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

4 ( 1.2 ) + 2 ( 1.3 ) + 1 ( 3.3 ) + 2 ( 1.7 ) 4 + 2 + 1 + 2

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

4 ( 1.3 ) + 2 ( 4.5 ) + 1 ( 4.4 ) + 2 ( 3.3 ) + 1 ( 1.7 ) + 2 ( 1.2 ) 4 + 2 + 1 + 2 + 1 + 2

The final array, result, would be

Chapter 7, Problem 21E, Write a static method blur (double [] [] picture) that you could use on a part of a picture file to , example  3

Blurred answer
Students have asked these similar questions
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.…
Suppose we have a 1-D array of Strings such that: • Each string records individual scores for different quizzes for one student. • Each string has the form "d1;d2;d3;.;dn;" where d1 to dn are all double values and they are separated using the character . Note that there is one ; after the last double value. • Each string contains the same number of double values. Write the method convert that takes a 1-D array of such Strings and an integer n as inputs, where n means the number of double values in each String in the array and returns a 2-D array containing doubie values. In the two 2-D array, each row records scores of one student and each column contains scores of one exam for all students. For example, if the parameters are ("1:2;3:4;", "5:6:7;8;", "9;10;11;12;") and 4, then the output would be a 3'4 2-D array which has the value ((1.0, 2.0, 3.0, 4.0), (5.0, 6.0, 7.0, 8.0), (9.0, 10.0, 11.0, 12.0). You are supposed to use the provided String library methods to operate these string…
I'm trying to write a Java program that stores a text file of integer values into a 2D array. The integers in each column are separated by commas. I also want to print out the 2D array after it is created this is the text file: Input.text 15, 50, 62, 72, 73, 74 58, 60, 70, 73, 76, 82 43, 59, 65, 72, 82, 65 18, 42, 63, 69, 73, 85

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License