Question: Please help me this JAVA question: This is the code for matrix I have so far.... But my instructor made it tougher, he said: Please
Please help me this JAVA question:
This is the code for matrix I have so far.... But my instructor made it tougher, he said: Please include a main method that tests all of your constructors and methods, including if the denominator == 0, he Added Fraction.java to the Code Examples block. This shows you a way to do the Exception Handling for the program, if you try to construct a fraction with denominator = 0. ( the fraction.java file is below the main code)
//This program will print the original matrix to standard output, //followed by the transpose of the matrix.
public class Matrix { public static void main(String[] args) { //Declare and initialize the 2D array "matrix[][]" int [ ][ ] matrix = new int[ ][ ] {{ 1, 2, 3, 4, 5}, { 6, 7, 8, 9, 10}, { 11, 12, 13, 14, 15}, { 16, 17, 18, 19, 20}, { 21, 22, 23, 24, 25}};
//Display original matrix System.out.println("Original Matrix:"); for(int i = 0;i for(int j = 0;j //this is the file fraction.java public class Fraction { int num; int denom; public Fraction(int numerator, int denominator) { try { if (denominator == 0) { throw new IllegalArgumentException("Cannot have a denominator = 0"); } } catch (IllegalArgumentException e) { System.out.println("Error: " + e.getMessage()); } } public static void main(String[] args) { // TODO Auto-generated method stub Fraction f = new Fraction(2, 0); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
