Created
December 6, 2024 22:37
-
-
Save MarioCares/6fcee73b0afcf7b043bc3a6404e4cdd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Genere test unitarios para comprobar las siguientes 2 clases: | |
public class Matematicas { | |
// Método para sumar dos números | |
public int sumar(int a, int b) { | |
return a + b; | |
} | |
// Método para restar dos números | |
public int restar(int a, int b) { | |
return a - b; | |
} | |
// Método para multiplicar dos números | |
public int multiplicar(int a, int b) { | |
return a * b; | |
} | |
// Método para dividir dos números | |
public double dividir(int a, int b) throws ArithmeticException { | |
if (b == 0) { | |
throw new ArithmeticException("División por cero no permitida"); | |
} | |
return (double) a / b; | |
} | |
} | |
//--------------------------- | |
public class OperacionesString { | |
// Método para concatenar dos cadenas | |
public String concatenar(String a, String b) { | |
return a + b; | |
} | |
// Método para verificar si una cadena está vacía | |
public boolean esVacia(String s) { | |
return s == null || s.isEmpty(); | |
} | |
// Método para convertir una cadena a mayúsculas | |
public String convertirAMayusculas(String s) { | |
if (s == null) { | |
return null; | |
} | |
return s.toUpperCase(); | |
} | |
// Método para obtener el primer carácter de una cadena | |
public char primerCaracter(String s) { | |
if (s == null || s.isEmpty()) { | |
throw new IllegalArgumentException("La cadena no puede estar vacía"); | |
} | |
return s.charAt(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment