You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This repository contains a Java project that performs operations on matrices of rational numbers. The project includes classes for defining rational numbers, handling matrix operations, and displaying results.
Features
Rational Number Representation: Defines rational numbers with methods for basic arithmetic operations.
Matrix Operations: Implements operations such as addition, subtraction, and multiplication for matrices of rational numbers.
User Interaction: Handles user input to create matrices and perform operations.
Result Display: Outputs the results of the matrix operations.
Code Snippets
Main Class
The main class initializes the program, handles user input, and invokes methods for matrix operations.
publicclassPrincipal {publicstaticvoidmain(String[]args) {Scannerscanner =newScanner(System.in);// Read matrix dimensionsSystem.out.print("Enter the number of rows: ");introws =scanner.nextInt();System.out.print("Enter the number of columns: ");intcols =scanner.nextInt();// Create and read matricesTMatrizRacionalmatrix1 =newTMatrizRacional(rows,cols);TMatrizRacionalmatrix2 =newTMatrizRacional(rows,cols);System.out.println("Enter the elements of the first matrix:");matrix1.readMatrix(scanner);System.out.println("Enter the elements of the second matrix:");matrix2.readMatrix(scanner);// Perform operationsTOpMatricesRacionalesoperations =newTOpMatricesRacionales();TMatrizRacionalsum =operations.add(matrix1,matrix2);TMatrizRacionaldifference =operations.subtract(matrix1,matrix2);TMatrizRacionalproduct =operations.multiply(matrix1,matrix2);// Display resultsSystem.out.println("Sum of matrices:");sum.printMatrix();System.out.println("Difference of matrices:");difference.printMatrix();System.out.println("Product of matrices:");product.printMatrix(); }}
Rational Number Class
TheTRacional class represents a rational number and includes methods for arithmetic operations and simplification.