Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
parte 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed May 18, 2024
1 parent 516bc0c commit f63d320
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,32 @@
import java.math.BigInteger;
import java.util.Optional;

import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.utp.clsHerramientas.parcial_2.ThreeNumbers;
import com.utp.utils.Result;

import static java.math.BigInteger.valueOf;

public class ClsPrinArch1Par2 {
public static void main(String[] args) {

ThreeNumbers numbers = App.leer_numeros();
Object[] resultados = new Object[4];
BigInteger expresion_1 = ClsPrinSumaPar2.MtdExpresion1Par2(numbers);
resultados[0] = String.format("El resultado de la primera expresión es: %s", expresion_1);
BigInteger expresion_2 = ClsPrinRestaPar2.MtdExpresion2Par2(numbers);
resultados[1] = String.format("El resultado de la segunda expresión es: %s", expresion_2);
// BigInteger multiplicacion = ClsSecArch1Par2.MtdDivision(numbers);
// resultados[2] = String.format("El resultado de la multiplicación es: %s",
// multiplicacion);
Optional<BigInteger> division = ClsSecArch1Par2.MtdDivision(numbers);
resultados[2] = division.map(value -> String.format("El resultado de la división es: %s", value))
.orElse("No se puede dividir por cero");
JOptionPane.showMessageDialog(null, resultados, "Resultados", JOptionPane.INFORMATION_MESSAGE);
}

BigInteger MtdExpresion1Par2(ThreeNumbers threeNumbers) {
static BigInteger MtdExpresion1Par2(ThreeNumbers threeNumbers) {

final BigInteger const_a = valueOf(3).divide(valueOf(5));
final BigInteger const_b = valueOf(1).divide(valueOf(2));
Expand All @@ -25,7 +42,7 @@ BigInteger MtdExpresion1Par2(ThreeNumbers threeNumbers) {
}

class ClsPrinRestaPar2 {
BigInteger MtdExpresion2Par2(ThreeNumbers threeNumbers) {
static BigInteger MtdExpresion2Par2(ThreeNumbers threeNumbers) {
final BigInteger const_a = valueOf(1).divide(valueOf(3));
final BigInteger const_b = valueOf(1).divide(valueOf(2));
final BigInteger const_c = valueOf(1).divide(valueOf(6));
Expand All @@ -37,15 +54,38 @@ BigInteger MtdExpresion2Par2(ThreeNumbers threeNumbers) {
}
}

class App {

static ThreeNumbers leer_numeros() {
JTextField[] entradas = new JTextField[] { new JTextField(), new JTextField(), new JTextField() };
Object[] elementos_de_entrada = new Object[] { "Ingrese el primer número", entradas[0],
"Ingrese el segundo número",
entradas[1], "Ingrese el tercer número", entradas[2] };
int confirm_dialog_result = JOptionPane.showConfirmDialog(null, entradas, "Ingrese los números");
BigIntger[] numeros = new BigInteger[3];

for (int i = 0; i < 3; i++) {
try {
numeros[i] = new BigInteger(entradas[i].getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null,
String.format("%s\nNo puede ser convertido a entero: `%s`", e.getMessage(), entradas[1]),
"Error de lectura", JOptionPane.ERROR_MESSAGE);
return leer_numeros();
}
}
return new ThreeNumbers(numeros[0], numeros[1], numeros[2]);
}
}

// class ClsSecArch1Par2{
// Optional<BigInteger> MtdDivision(ThreeNumbers threeNumbers) {
// var num1 = threeNumbers.num1();
// var num2 = threeNumbers.num2();
// var num3 = threeNumbers.num3();
// if (num3.equals(BigInteger.ZERO)) {
// return Optional.empty();
// }
// return Optional.of(num1.multiply(num2).divide(num3));
// }
// Optional<BigInteger> MtdDivision(ThreeNumbers threeNumbers) {
// var num1 = threeNumbers.num1();
// var num2 = threeNumbers.num2();
// var num3 = threeNumbers.num3();
// if (num3.equals(BigInteger.ZERO)) {
// return Optional.empty();
// }
// return Optional.of(num1.multiply(num2).divide(num3));
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.utp.clsHerramientas.parcial_2.ThreeNumbers;

class ClsMultArch1Par2 {
BigInteger MtdMultPar2(ThreeNumbers threeNumbers) {
static BigInteger MtdMultPar2(ThreeNumbers threeNumbers) {
var num1 = threeNumbers.num1();
var num2 = threeNumbers.num2();
var num3 = threeNumbers.num3();
Expand Down

0 comments on commit f63d320

Please sign in to comment.