Skip to content

Commit

Permalink
Testing java version
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Mar 15, 2024
1 parent f6b0386 commit f97924f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
74 changes: 64 additions & 10 deletions packages/java/src/main/java/io/github/gabriel_logan/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,71 @@
package io.github.gabriel_logan;

import io.github.gabriel_logan.types.ValidationResult;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
private String getErrorMessage(int code) {
// Implemente esta função para retornar a mensagem de erro apropriada
return "";
}

/**
* Checks if a string is empty or contains only whitespace.
*
* @param value the string to check
* @return true if the string is empty or contains only whitespace, false otherwise
* @throws IllegalArgumentException if the input value is not a string
*/
public static boolean isEmpty(String value) throws IllegalArgumentException {
if (value == null) {
throw new IllegalArgumentException("Input value must be a string.");
}

return value.trim().length() == 0;
}

public ValidationResult cpfIsValid(String cpf) {
try {
int numeroBase = 10;
int numeroBase2 = 11;
int somaTotal = 0;
int somaTotal2 = 0;

if (cpf.length() != 11) {
return new ValidationResult(false, getErrorMessage(2));
}

int primeiroVerificador = 0;
int segundoVerificador = 0;

for (int repetidor = 0; repetidor < 11; repetidor++) {
int multiplicador = Character.getNumericValue(cpf.charAt(repetidor)) * numeroBase;
numeroBase--;
somaTotal += multiplicador;

int multiplicador2 = Character.getNumericValue(cpf.charAt(repetidor)) * numeroBase2;
numeroBase2--;
somaTotal2 += multiplicador2;

int valorDeVerificacao = somaTotal - Character.getNumericValue(cpf.charAt(9));
int valorDeVerificacao2 = somaTotal2 - Character.getNumericValue(cpf.charAt(10));

primeiroVerificador = 11 - (valorDeVerificacao % 11);
segundoVerificador = 11 - (valorDeVerificacao2 % 11);
}

if (primeiroVerificador > 9) primeiroVerificador = 0;
if (segundoVerificador > 9) segundoVerificador = 0;

if (primeiroVerificador == Character.getNumericValue(cpf.charAt(9))
&& segundoVerificador == Character.getNumericValue(cpf.charAt(10))) {
return new ValidationResult(true, null);
}

return new ValidationResult(false, getErrorMessage(2));
} catch (Exception e) {
return new ValidationResult(false, getErrorMessage(3));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.gabriel_logan;

public class ValidationResult {
public boolean isValid;
public String errorMsg;

public ValidationResult(boolean isValid, String errorMsg) {
this.isValid = isValid;
this.errorMsg = errorMsg;
}
}

0 comments on commit f97924f

Please sign in to comment.