Advertisement
robeeeert

Untitled

Jun 15th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.89 KB | None | 0 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  */
  4.  
  5. package com.mycompany.validar;
  6.  
  7. /**
  8.  *
  9.  * @author ianto
  10.  */
  11. import java.io.BufferedReader;
  12. import java.io.BufferedWriter;
  13. import java.io.File;
  14. import java.io.FileReader;
  15. import java.io.FileWriter;
  16. import java.io.IOException;
  17. import java.util.*;
  18. public class Validar {
  19.  
  20.     public static void main(String[] args) {
  21.         Scanner entrada = new Scanner(System.in);
  22.         System.out.println("Ingrese fecha");
  23.         String fecha = entrada.nextLine();
  24.         while(!validarFecha(fecha)){
  25.             System.out.println("fecha no valida");
  26.             System.out.println("Ingrese fecha nuevamente");
  27.             fecha = entrada.nextLine();
  28.         }
  29.         System.out.println("fecha correcta");
  30.     }
  31.     public static boolean validarFecha(String fecha){
  32.         boolean fechavalida = true;
  33.         String[] partesfecha = fecha.split("/");
  34.         int dia = Integer.parseInt(partesfecha[0]);
  35.         int mes = Integer.parseInt(partesfecha[1]);
  36.         int año = Integer.parseInt(partesfecha[2]);
  37.         if(fecha.length() >10){
  38.             fechavalida = false;
  39.         }
  40.         if(mes < 1 || mes > 12){
  41.             fechavalida = false;
  42.         }else{
  43.             switch(mes){
  44.                 case 2:
  45.                     if(esBisiesto(año)){
  46.                         if(dia<1 || dia<29){
  47.                             fechavalida = false;
  48.                         }
  49.                     }else{
  50.                         if(dia<1 || dia>28)
  51.                         fechavalida = false;
  52.                         }
  53.                     break;
  54.                 case 4: case 6: case 9: case 11:
  55.                     if(dia <1 || dia >30){
  56.                         fechavalida = false;
  57.                     }
  58.                     break;
  59.                 default:
  60.                     if(dia < 1 || dia >31){
  61.                         fechavalida = false;
  62.                     }
  63.                     break;
  64.             }
  65.         }
  66.         return fechavalida;
  67.     }
  68.     public static boolean esBisiesto(int año){
  69.         return(año % 4 == 0 && año %100 != 0) || (año % 400 == 0);
  70.     }
  71.     public static boolean validarcui(String cui){
  72.         int contador = 0;
  73.         boolean cuivalido = false;
  74.         String ultimosCuatroDigitos;
  75.         if (cui.length() == 13){
  76.             for(int i = 0; i <cui.length(); i++){
  77.                 if (i == 0){
  78.                     switch(cui.charAt(i)){
  79.                         case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
  80.                             contador ++;
  81.                             break;
  82.                     }
  83.                 }
  84.                 switch(i){
  85.                     case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
  86.                         switch(cui.charAt(i)){
  87.                             case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
  88.                                 contador ++;
  89.                                 break;
  90.                         }
  91.                 }
  92.             }
  93.         }
  94.         ultimosCuatroDigitos = cui.substring(9);
  95.         if(contador == cui.length())
  96.             if(!buscarEnArchivo(ultimosCuatroDigitos)){
  97.                 cuivalido = false;
  98.             }else{
  99.                 cuivalido = true;
  100.             }
  101.         return cuivalido;
  102.     }
  103.     public static boolean buscarEnArchivo(String ultimosCuatroDigitos){
  104.         boolean encontrado = false;
  105.         try{
  106.             BufferedReader br = new BufferedReader(new FileReader("DepartamentosMunicipios.txt"));
  107.             String linea;
  108.             while ((linea = br.readLine()) != null){
  109.                 if (linea.length() >= 4){
  110.                     String codigo = linea.substring(0,4);
  111.                     if(codigo.equals(ultimosCuatroDigitos)){
  112.                         encontrado = true;
  113.                         break;
  114.                     }
  115.                
  116.                    
  117.                 }
  118.             }
  119.         }catch(IOException e){
  120.             System.out.println("No se encontro el archivo");
  121.         }
  122.         return encontrado;
  123.     }
  124. }
  125. import java.util.Stack;
  126. import java.io.*;
  127. public class ArchivoPilas {
  128.     Stack<Clientes> pilaVentas = new Stack<>();
  129.     Stack<Clientes> pilaCompras = new Stack<>();
  130.     Stack<Clientes> pilaConta = new Stack<>();
  131.     Stack<Clientes> pilaSiste = new Stack<>();
  132.     public void ingresarCliente(Clientes cliente){
  133.         try{
  134.             File f = new File("Clientes_10062023.txt");
  135.             FileWriter fw;
  136.             BufferedWriter bw;
  137.             if (f.exists() & (f.length() !=0)){
  138.                 fw = new FileWriter(f,true);
  139.                 bw = new BufferedWriter(fw);
  140.                 bw.newLine();  
  141.             }else{
  142.                 fw = new FileWriter(f);
  143.                 bw = new BufferedWriter(fw);  
  144.             }
  145.             bw.write(cliente.getNit());
  146.             bw.write("%");
  147.             bw.write(cliente.getNombres());
  148.             bw.write("%");
  149.             bw.write(cliente.getApellidos());
  150.             bw.write("%");
  151.             bw.write(cliente.getFechaNacimiento());
  152.             bw.write("%");
  153.             bw.write(cliente.getGenero());
  154.             bw.write("%");
  155.             bw.write(cliente.getDepartamento());
  156.             bw.close();
  157.             fw.close();
  158.         }catch(Exception e){
  159.             System.out.println("Error de E/S " + e);
  160.         }
  161.     }
  162.     public void cargarClientes(){
  163.         try{
  164.             File f = new File ("Clientes_10062023.txt");
  165.             if (f.exists()){
  166.                     FileReader fr = new FileReader(f);
  167.                     BufferedReader br = new BufferedReader(fr);
  168.                     String linea;
  169.                     while((linea = br.readLine()) !=null){
  170.                         String[] arreglo = linea.split("%");
  171.                         Clientes cliente = new Clientes(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
  172.                         switch(cliente.getDepartamento()){
  173.                             case "1":
  174.                                 pilaVentas.push(cliente);
  175.                                 break;
  176.                             case "2":
  177.                                 pilaCompras.push(cliente);
  178.                                 break;
  179.                             case "3":
  180.                                 pilaConta.push(cliente);
  181.                                 break;
  182.                             case "4":
  183.                                 pilaSiste.push(cliente);
  184.                                 break;
  185.                         }
  186.                     }//while
  187.                     br.close();
  188.                     fr.close();
  189.             }//if
  190.         }catch(Exception e){
  191.                 System.out.println("Error de S/E" + e);
  192.         }//TryCatch
  193.     }
  194.     public void mostrarClientes(){
  195.         while(!pilaVentas.empty()){
  196.             System.out.println("\tClientes Ventas En Pila:\n"+ pilaVentas+"\n");
  197.             break;
  198.         }
  199.         while(!pilaCompras.empty()){
  200.             System.out.println("\tClientes Compras En Pila:\n"+ pilaCompras+"\n");
  201.             break;
  202.         }
  203.         while(!pilaConta.empty()){
  204.             System.out.println("\tClientes Conta En Pila:\n"+ pilaConta+"\n");
  205.             break;
  206.         }
  207.         while(!pilaSiste.empty()){
  208.             System.out.println("\tCliente Sistemas En Pila:\n"+ pilaSiste+"\n");
  209.             break;
  210.         }
  211.     }
  212.     public void atenderVentas(){
  213.         if(!pilaVentas.empty()) {
  214.             Clientes cliente = pilaVentas.peek();
  215.             System.out.println("Atendiendo Al Cliente En Ventas: " + cliente.toString());
  216.             pilaVentas.pop();
  217.         }else{
  218.         System.out.println("No Hay Clientes En La Pila Ventas.");
  219.         }
  220.     }
  221.     public void atenderCompras(){
  222.         if(!pilaCompras.empty()) {
  223.             Clientes cliente = pilaCompras.peek();
  224.             System.out.println("Atendiendo Al Cliente En Compras: " + cliente.toString());
  225.             pilaCompras.pop();
  226.         }else{
  227.         System.out.println("No Hay Clientes En La Pila Compras.");
  228.         }
  229.     }
  230.     public void atenderConta(){
  231.         if(!pilaConta.empty()) {
  232.             Clientes cliente = pilaConta.peek();
  233.             System.out.println("Atendiendo Al Cliente En Contabilidad: " + cliente.toString());
  234.             pilaConta.pop();
  235.         }else{
  236.         System.out.println("No Hay Clientes En La Pila Contabilidad.");
  237.         }
  238.     }
  239.     public void atenderSiste(){
  240.         if(!pilaSiste.empty()) {
  241.             Clientes cliente = pilaSiste.peek();
  242.             System.out.println("Atendiendo Al Cliente En Sistemas: " + cliente.toString());
  243.             pilaSiste.pop();
  244.         }else{
  245.         System.out.println("No Hay Clientes En La Pila Sistemas.");
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement