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 (1.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 Examplel 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}} 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 (1.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 Examplel 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}}
Expert 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
-
2 What are the zeros of f(x) = 12 cosx-3 on the interval [0,2]? The zeros are (Type an exact answer in terms of . Use a comma to separate answers as needed.)
-
Jamie is employed in Qubec and earns $2,300.00 semi-monthly. Her TD1 claim code is 2, and her TP-1015.3-V deduction code is B. Calculate her total deductions this pay period. Your answer Previous...
-
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...
-
What does this code print (unless it produces an error)? = plane "A passengers" plane [2] = "m" print (plane)
-
Suppose a firm is considering two mutually exclusive projects. One has a life of 6 years and the other a life of 10 years. Would the failure to employ some type of replacement chain analysis bias an...
-
1. Define pure economic rent. 2. Explain why the supply curve of land can be upwardsloping when there is a fixed quantity of land in the world. 3. Define artificial rent. 4. Define real rent. 5....
-
Rank in order from brightest to dimmest, the identical bulbs A to D. A B D
-
Prepare any necessary adjusting entries at December 31, 2013, for Maxum Companys year- end financial statements for each of the following separate transactions and events. 1. Employees earn vacation...
-
Monthly Salary: $5,000 Deposit: 2% of monthly salary towards college account Yearly Salary: increases by 1% every year College Account is paying 4% interest compounded monthly. How much money will...
-
The number of accidents on a road per day is recorded for 80 days, giving the following results. It is thought that the dataset models a Poisson distribution with a rate of 2.5 accidents per day....
-
Aug 31 Prepare the required entry to Receiver General for the Payment/Refund of HST for the month of August 2023. Hint : Run a Trial Balance to get the figures needed for the entry.
-
2. Assume the U.S. dollar returns (monthly averages) shown below for the three European countries. Market Mean Return (R, %) Risk-Free Rate (rfr, %) Standard Deviation (0) Country Beta (B) Slovenia...
-
How do you set up sales tax for the provinces in which you do business if they are somewhere other than where your business is located?
-
Which costing category includes training departments' administrative salaries and training facility maintenance?
-
If this artwork were translated into an auditory form, what tonal qualities and melodic intricacies would characterize its hypothetical musical rendition?
-
I want a program to take input from user and build a new class that inherits existing parent class and its functions. is it possible to do so, if yes how do i do that? (Please include a short code)....
-
2. ABC Company has two projects: A: It is considering to purchase an equipment to be attached with the main manufacturing machine. The equipment will cost $6,000 and will have annual cash inflow by...
-
A parking lot charges $3 for the first hour (or part of an hour) and $2 for each succeeding hour (or part), up to a daily maximum of $10. (a) Sketch a graph of the cost of parking at this lot as a...
-
Develop an algorithm for computing the month-by-month balance in your savings account. You can make one transactiona deposit or a withdrawal each month. Interest is added to the account at the...
-
The following code fragment will not compile. Why? if !x > x + y x = 2 * x; else x = x + 3;
-
Given that the int variable temp contains a temperature that is not negative, write a Java statement that uses the conditional operator to set the String variablelabel to either "degree" or...
-
What is the advantage of being able to produce spores, as many bacteria do?
-
What is a chemoautotroph? What does a chemoautotroph have in common with a plant? How does a chemoautotroph differ from a plant in how it obtains food?
-
What is the difference between a heterotroph and an autotroph? Name a clade of living things that consists exclusively of heterotrophs and one that consists exclusively of autotrophs. Name a clade...
Study smarter with the SolutionInn App