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 for performing arithmetic operations on rational numbers and operations on matrices of rational numbers. The project includes classes for defining rational numbers, handling matrix operations, and managing user input to display the results.
Features
Rational Number Representation: Defines rational numbers with methods for basic arithmetic operations and simplification.
Matrix Operations: Implements operations such as addition, subtraction, and multiplication for matrices of rational numbers.
User Interaction: Handles user input to create rational numbers and matrices and perform various operations.
Result Display: Outputs the results of arithmetic and matrix operations.
Code Snippets
Main Class
The main class initializes the program, handles user input, and invokes methods for arithmetic and matrix operations.
publicclassPrincipal {publicstaticvoidmain(String[]args) {Scannerscanner =newScanner(System.in);// Rational number operationsSystem.out.print("Enter numerator for the first rational number: ");intnum1 =scanner.nextInt();System.out.print("Enter denominator for the first rational number: ");intden1 =scanner.nextInt();TRacionalr1 =newTRacional(num1,den1);System.out.print("Enter numerator for the second rational number: ");intnum2 =scanner.nextInt();System.out.print("Enter denominator for the second rational number: ");intden2 =scanner.nextInt();TRacionalr2 =newTRacional(num2,den2);TOperaRacionalesops =newTOperaRacionales();System.out.println("Sum: " +ops.add(r1,r2));System.out.println("Difference: " +ops.subtract(r1,r2));System.out.println("Product: " +ops.multiply(r1,r2));System.out.println("Quotient: " +ops.divide(r1,r2));// Matrix operationsSystem.out.print("Enter the number of rows for the matrices: ");introws =scanner.nextInt();System.out.print("Enter the number of columns for the matrices: ");intcols =scanner.nextInt();TMatrizRacionalm1 =newTMatrizRacional(rows,cols);TMatrizRacionalm2 =newTMatrizRacional(rows,cols);System.out.println("Enter elements for the first matrix:");m1.readMatrix(scanner);System.out.println("Enter elements for the second matrix:");m2.readMatrix(scanner);TOpMatricesRacionalesmatrixOps =newTOpMatricesRacionales();System.out.println("Matrix Sum:");matrixOps.add(m1,m2).printMatrix();System.out.println("Matrix Difference:");matrixOps.subtract(m1,m2).printMatrix();System.out.println("Matrix Product:");matrixOps.multiply(m1,m2).printMatrix(); }}
Rational Number Class
TheTRacional class represents a rational number and includes methods for arithmetic operations and simplification.