Write a method named normalize() that accepts an argument which is reference to a two-dimensional (2D)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a method named normalize() that accepts an argument which is reference to a two-dimensional (2D) NxN array with elements of type double. In fact, the 2D array represents a square matrix (i.e., the number of rows is equal to the number of columns). The method should return a resulting 2D array of elements of type double, which is derived by the following instructions. a) The method first finds the difference between the average of its diagonals. Example1: {{1, 2, 3}, {4, 5, 6}, {1, 8, 9}} Average of first diagonal = (1+5+9)/ 3 = 5 Average of second diagonal = (3+5+1)/3 = 3 Difference = 5 - 3 = 2 Example2: {{1, 2, 3), (3, 4, 5), (5, 6, 7}} Average of first diagonal = (1+4+7)/ 3 = 4 Average of second diagonal = (3+4+5)/3 = 4 Difference = 4 -4 = 0 b) Use try-catch blocks to do the following. • If the difference found in step (a) is not 0, then divide each element of array by the difference found in (a). . • If the difference found in step (a) is 0, then throw an appropriate exception, and print "Runtime Exception" in the catch block and leave the array as is. c) Return the array derived in step (b). For Example1 in (a), the method returns the array: {{0.5, 1.0, 1.5), (2.0, 2.5, 3.0), (0.5, 4.0, 4.5}} For Example2 in (a), the method prints Runtime Exception and returns the array: {[1.0, 2.0, 3.0), (3.0, 4.0, 5.0), (5.0, 6.0, 7.0}} Submission instructions: Please submit only the java code for the method normalize() in the answer textbox by cut/paste or by directly coding in the textbox. Write a method named normalize() that accepts an argument which is reference to a two-dimensional (2D) NxN array with elements of type double. In fact, the 2D array represents a square matrix (i.e., the number of rows is equal to the number of columns). The method should return a resulting 2D array of elements of type double, which is derived by the following instructions. a) The method first finds the difference between the average of its diagonals. Example1: {{1, 2, 3}, {4, 5, 6}, {1, 8, 9}} Average of first diagonal = (1+5+9)/ 3 = 5 Average of second diagonal = (3+5+1)/3 = 3 Difference = 5 - 3 = 2 Example2: {{1, 2, 3), (3, 4, 5), (5, 6, 7}} Average of first diagonal = (1+4+7)/ 3 = 4 Average of second diagonal = (3+4+5)/3 = 4 Difference = 4 -4 = 0 b) Use try-catch blocks to do the following. • If the difference found in step (a) is not 0, then divide each element of array by the difference found in (a). . • If the difference found in step (a) is 0, then throw an appropriate exception, and print "Runtime Exception" in the catch block and leave the array as is. c) Return the array derived in step (b). For Example1 in (a), the method returns the array: {{0.5, 1.0, 1.5), (2.0, 2.5, 3.0), (0.5, 4.0, 4.5}} For Example2 in (a), the method prints Runtime Exception and returns the array: {[1.0, 2.0, 3.0), (3.0, 4.0, 5.0), (5.0, 6.0, 7.0}} Submission instructions: Please submit only the java code for the method normalize() in the answer textbox by cut/paste or by directly coding in the textbox.
Expert Answer:
Answer rating: 100% (QA)
Logic to implement this method initialize sum of diagonals to 0 loop from i0 to i add value at row i ... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Two-dimensional array operations: Movie Ratings program ** You have recently collected reviews from four movie reviewers where the reviewers are numbered 1-4. Each reviewer has rated six movies where...
-
. A vertical pole that is 2 meters tall casts a shadow that is 1.5 meters long. Nearby, at the same time, another vertical pole casts a shadow that is 6.5 meters long. How tall is this pole? a. Make...
-
9.1 Exercise (JDK Source Code): Extract the source code of the class Math from the JDK source code ("$JAVA_HOME" "src.zip" "Math.java" under folder "java.lang"). Study how constants such as E and...
-
Jake, a single taxpayer, has $100,000 of ordinary income, a $10,000 net short-term capital loss, and $7,000 of qualified dividends. What is the result?
-
Suppose Harry Davis issues 30-year debt with a par value of $1,000 and a coupon rate of 10%, paid annually. If flotation costs are 2%, what is the after-tax cost of debt for the new bond?
-
Which of these are Scrum anti patterns? Select the correct option(s) and click Submit. Programmers as one Scrum Team and Testers as another Scrum Team Scrum Master as a servant leader Scrum Team with...
-
Which of the curves in Figure P22.72 best represents the expected variation in current as a function of time in the short time interval immediately after the bulb is turned on? You've probably...
-
H.J. Heinz Company uses standards to control its materials costs. Assume that a batch of ketchup (1,500 pounds) has the following standards: The actual materials in a batch may vary from the standard...
-
All of the following are 'principles of prudence' EXCEPT for: Group of answer choices Trustees have a duty to determine the appropriate levels of risk. Trustees have a duty to avoid high fees. Sound...
-
Kelly Consulting Post-Closing Trial Balance April 30, 20Y8 Account number Debit Credit Money 11 22,100 accounts receivable 12 3,400 supplies 14 1,350 prepaid rent 15 3,200 prepaid insurance sixteen...
-
Resources that will help solve the problem can be found at http://www.youtube.com/watch?v=DTMxjANGvcU Complete the following tables and upload with answers included. SEE ATTACHED FILE: Retirement...
-
The body-fixed xyz axes pass through the center of mass G of the airplane and are the principal axes of inertia. The moments of inertia about these axes are A , B , and C , respectively. The airplane...
-
How does the concept of spectralism manifest within contemporary orchestral compositions, particularly regarding the deliberate manipulation of sound spectra and the intricate synthesis of harmonic...
-
You are to evaluate two mutually exclusive business projects with expected cash flows described below. Assuming a 10% weighted average cost of capital (WACC), calculate NPV and IRR for each project...
-
How does polyphony influence the structural complexity of Renaissance vocal compositions, and what distinguishes it from homophonic textures?
-
The table below shows rates on zero-coupon Treasury securities: Maturity (years) Yield 1 3.1% 2 4.4% 3 5.4% Calculate the expected two year rate at the end of the first year (22). Round your final...
-
20X9 ASSETS CURRENT Cash 564,911 Trade and other receivables 8,158,139 Unbilled revenue 2,679,949 11,402,998 EQUIPMENT ( Note 3 ) 541,404 $ 11,944,402 LIABILITIES CURRENT Bank indebtedness - Trade...
-
Prove that if Σ an is absolutely convergent, then a. an
-
Write a fragment of code that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterwards.
-
Write a recursive method that will duplicate each character in a string and return the result as a new string. For example, if "book" is the argument, the result would be "bbooookk".
-
Repeat Exercise 1 for a credit card account instead of a credit card. An account represents the charges and payments made using a credit card. Exercise 1 Design a class to represent a credit card....
-
For the periodic processes shown below: a. Schedule the processes using an RMS policy. b. Schedule the processes using an EDF policy. In each case, compute the schedule for an interval equal to the...
-
For the periodic processes shown below: a. Schedule the processes using an RMS policy. b. Schedule the processes using an EDF policy. In each case, compute the schedule for an interval equal to the...
-
For the given periodic process execution times and periods (P1 has the highest priority), show how much CPU time of higher-priority processes will be required during one period of each of the...
Study smarter with the SolutionInn App