Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean validarCui(String cui) {
- int contadorDigitos = 0;
- boolean cuiValido = false;
- String ultimosCuatroDigitos;
- if (cui.length() == 13) {
- for (int i = 0; i < cui.length(); i++) {
- if (i == 0) {
- switch (cui.charAt(i)) {
- case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- contadorDigitos++;
- break;
- }
- }
- switch (i) {
- case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
- switch (cui.charAt(i)) {
- case '0':case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- contadorDigitos++;
- break;
- }
- }
- }
- }
- ultimosCuatroDigitos = cui.substring(9);
- if (contadorDigitos == cui.length()) {
- if (!buscarEnArchivo(ultimosCuatroDigitos)) {
- cuiValido = false;
- } else {
- cuiValido = true;
- }
- }
- return cuiValido;
- }
- public static boolean buscarEnArchivo(String ultimosCuatroDigitos) {
- boolean codigoEncontrado = false;
- try {
- BufferedReader br = new BufferedReader(new FileReader("DepartamentosMunicipios.txt"));
- String linea;
- while ((linea = br.readLine()) != null) {
- if (linea.length() >= 4) {
- String codigo = linea.substring(0, 4);
- if (codigo.equals(ultimosCuatroDigitos)) {
- codigoEncontrado = true;
- break;
- }
- }
- }
- } catch (IOException e) {
- System.out.println("No se encontro el archivo");
- }
- return codigoEncontrado;
- }
- public static boolean validarFecha(String fecha){
- boolean fechaValida = true;
- String[] partesFecha = fecha.split("/");
- int dia = Integer.parseInt(partesFecha[0]);
- int mes = Integer.parseInt(partesFecha[1]);
- int año = Integer.parseInt(partesFecha[2]);
- if (fecha.length() > 10){
- fechaValida = false;
- }
- if(mes < 1 || mes > 12 ){
- fechaValida = false;
- }else{
- switch(mes){
- case 2:
- if(esBisiesto(año)){
- if(dia < 1 || dia > 29){
- fechaValida = false;
- }
- }else{
- if(dia < 1 || dia > 28){
- fechaValida = false;
- }
- }
- break;
- case 4: case 6: case 9: case 11:
- if(dia < 1 || dia > 30){
- fechaValida = false;
- }
- break;
- default:
- if(dia < 1 || dia > 31){
- fechaValida = false;
- }
- break;
- }
- }
- return fechaValida;
- }
- public static boolean esBisiesto(int año){
- return (año % 4 == 0 && año % 100 != 0) || (año % 400 == 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement