Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 package option2; 3 inport java.util.ArrayList; 5 public class Matrix t private ArrayList) /TO BE COMPLETED 26 s create a matrix of nRows rows and

image text in transcribedimage text in transcribedimage text in transcribed

1 package option2; 3 inport java.util.ArrayList; 5 public class Matrix t private ArrayList) /TO BE COMPLETED 26 s create a matrix of nRows rows and nCols columns s eparan nRows x eparan ncols 28 29 public Matrix(int nRows, int nCols) 31 /TO BE COMPLETED 35 36 37 assumption values is a valid string s (contains double values separated by space) For example, 1.5 2.4 5.6 7.1 47.8" 39 40 41 If the number of items in values is square of an integer, it creates a square matrix. For example,"1 2 3 4" would create matrix 43 *1 2 3 4 45 47 48 49 If the number of items in values is not square of an integer, it tries to create a matrix of size 2 by (values. length/2). If not possible then, 3 by (values. length/3). If not possible then, 51 52 53 and in the worst case scenario, it creates a matrix of size values.length by 1 x For exanple, "1 2 34 5 6" would create matrix 1 2 3 4 5 6 56 58 59 while "1 2 3 456 7" would create the matrix 4 63 64 s @paran values 69 70 71 public Matrix(String values) data-new ArrayList) /TO BE COMPLETED 73 75 76 s construct the matrix as a clone of the source matrix eparan source 73 public Matrix(Matrix source) datanew ArrayLists ArrayList-Double> ; /TO BE COMPLETED 80 81 83 84 85 86 87 DO NOT MODIFY @paran row @paran column x @return the value at given row and column if any return null if the location is invalid 89 0 public Double get(int row, int column) t if(isValid(row, column)) 92 93 return null; return data.get (row).get (column); 95

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago