Define the exceptions that are necessary to catch the possible errors that can occur in the class Matrix · ExceptionWrongMatrixValues that is thrown in the method read() if the data on the String does not correspond to numeric values, or if the data are not consistent with the form of a matrix (e.g., the rows have different length); voontic throum in th the

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

Subject: Object Oriented Prgramming
Language: Java 
Topic: Exception

(SEE ATTACHED PHOTO FOR THE PROBLEM)

 

Initial code to be completed:

public class Matrix{
    private int matrix[][];
    
    public Matrix(){}
    
    public Matrix(int row, int column){
        matrix = new int[row][column];
    }
    
    //your methods here
}

Define the exceptions that are necessary to catch the possible errors that can occur in the
class Matrix
· ExceptionWrongMatrixValues that is thrown in the method read() if the data on the String
does not correspond to numeric values, or if the data are not consistent with the form of a
matrix (e.g., the rows have different length);
· ExceptionWrongMatrixDimension that is thrown in the method read() if the data on the
String do not correspond to the dimension of the matrix.
The numbers are separated by space. A dot in a string means the next string of text is for the
next row.
For example:
Test
Result
String input="1 2 3 .1e 3.";
ExceptionWrongMatrixValues
Matrix m = new Matrix ();
m.read (input);
String input="1 2 3. 1 2 3 4 5 ."; ExceptionWrongMatrixValues
Matrix m = new Matrix ();
m.read (input);
String input="12312345";
ExceptionWrongMatrixDimension
Matrix m = new Matrix ();
m.read (input);
String input="1 2.3 4.";
1 2
Matrix m = new Matrix ();
3 4
m.read (input);
Transcribed Image Text:Define the exceptions that are necessary to catch the possible errors that can occur in the class Matrix · ExceptionWrongMatrixValues that is thrown in the method read() if the data on the String does not correspond to numeric values, or if the data are not consistent with the form of a matrix (e.g., the rows have different length); · ExceptionWrongMatrixDimension that is thrown in the method read() if the data on the String do not correspond to the dimension of the matrix. The numbers are separated by space. A dot in a string means the next string of text is for the next row. For example: Test Result String input="1 2 3 .1e 3."; ExceptionWrongMatrixValues Matrix m = new Matrix (); m.read (input); String input="1 2 3. 1 2 3 4 5 ."; ExceptionWrongMatrixValues Matrix m = new Matrix (); m.read (input); String input="12312345"; ExceptionWrongMatrixDimension Matrix m = new Matrix (); m.read (input); String input="1 2.3 4."; 1 2 Matrix m = new Matrix (); 3 4 m.read (input);
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Custom Exception class
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
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT