Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- */
- package com.mycompany.validar;
- /**
- *
- * @author ianto
- */
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.*;
- public class Validar {
- public static void main(String[] args) {
- Scanner entrada = new Scanner(System.in);
- System.out.println("Ingrese fecha");
- String fecha = entrada.nextLine();
- while(!validarFecha(fecha)){
- System.out.println("fecha no valida");
- System.out.println("Ingrese fecha nuevamente");
- fecha = entrada.nextLine();
- }
- System.out.println("fecha correcta");
- }
- 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);
- }
- public static boolean validarcui(String cui){
- int contador = 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':
- contador ++;
- 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':
- contador ++;
- break;
- }
- }
- }
- }
- ultimosCuatroDigitos = cui.substring(9);
- if(contador == cui.length())
- if(!buscarEnArchivo(ultimosCuatroDigitos)){
- cuivalido = false;
- }else{
- cuivalido = true;
- }
- return cuivalido;
- }
- public static boolean buscarEnArchivo(String ultimosCuatroDigitos){
- boolean encontrado = 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)){
- encontrado = true;
- break;
- }
- }
- }
- }catch(IOException e){
- System.out.println("No se encontro el archivo");
- }
- return encontrado;
- }
- }
- import java.util.Stack;
- import java.io.*;
- public class ArchivoPilas {
- Stack<Clientes> pilaVentas = new Stack<>();
- Stack<Clientes> pilaCompras = new Stack<>();
- Stack<Clientes> pilaConta = new Stack<>();
- Stack<Clientes> pilaSiste = new Stack<>();
- public void ingresarCliente(Clientes cliente){
- try{
- File f = new File("Clientes_10062023.txt");
- FileWriter fw;
- BufferedWriter bw;
- if (f.exists() & (f.length() !=0)){
- fw = new FileWriter(f,true);
- bw = new BufferedWriter(fw);
- bw.newLine();
- }else{
- fw = new FileWriter(f);
- bw = new BufferedWriter(fw);
- }
- bw.write(cliente.getNit());
- bw.write("%");
- bw.write(cliente.getNombres());
- bw.write("%");
- bw.write(cliente.getApellidos());
- bw.write("%");
- bw.write(cliente.getFechaNacimiento());
- bw.write("%");
- bw.write(cliente.getGenero());
- bw.write("%");
- bw.write(cliente.getDepartamento());
- bw.close();
- fw.close();
- }catch(Exception e){
- System.out.println("Error de E/S " + e);
- }
- }
- public void cargarClientes(){
- try{
- File f = new File ("Clientes_10062023.txt");
- if (f.exists()){
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- String linea;
- while((linea = br.readLine()) !=null){
- String[] arreglo = linea.split("%");
- Clientes cliente = new Clientes(arreglo[0], arreglo[1], arreglo[2], arreglo[3],arreglo[4],arreglo[5]);
- switch(cliente.getDepartamento()){
- case "1":
- pilaVentas.push(cliente);
- break;
- case "2":
- pilaCompras.push(cliente);
- break;
- case "3":
- pilaConta.push(cliente);
- break;
- case "4":
- pilaSiste.push(cliente);
- break;
- }
- }//while
- br.close();
- fr.close();
- }//if
- }catch(Exception e){
- System.out.println("Error de S/E" + e);
- }//TryCatch
- }
- public void mostrarClientes(){
- while(!pilaVentas.empty()){
- System.out.println("\tClientes Ventas En Pila:\n"+ pilaVentas+"\n");
- break;
- }
- while(!pilaCompras.empty()){
- System.out.println("\tClientes Compras En Pila:\n"+ pilaCompras+"\n");
- break;
- }
- while(!pilaConta.empty()){
- System.out.println("\tClientes Conta En Pila:\n"+ pilaConta+"\n");
- break;
- }
- while(!pilaSiste.empty()){
- System.out.println("\tCliente Sistemas En Pila:\n"+ pilaSiste+"\n");
- break;
- }
- }
- public void atenderVentas(){
- if(!pilaVentas.empty()) {
- Clientes cliente = pilaVentas.peek();
- System.out.println("Atendiendo Al Cliente En Ventas: " + cliente.toString());
- pilaVentas.pop();
- }else{
- System.out.println("No Hay Clientes En La Pila Ventas.");
- }
- }
- public void atenderCompras(){
- if(!pilaCompras.empty()) {
- Clientes cliente = pilaCompras.peek();
- System.out.println("Atendiendo Al Cliente En Compras: " + cliente.toString());
- pilaCompras.pop();
- }else{
- System.out.println("No Hay Clientes En La Pila Compras.");
- }
- }
- public void atenderConta(){
- if(!pilaConta.empty()) {
- Clientes cliente = pilaConta.peek();
- System.out.println("Atendiendo Al Cliente En Contabilidad: " + cliente.toString());
- pilaConta.pop();
- }else{
- System.out.println("No Hay Clientes En La Pila Contabilidad.");
- }
- }
- public void atenderSiste(){
- if(!pilaSiste.empty()) {
- Clientes cliente = pilaSiste.peek();
- System.out.println("Atendiendo Al Cliente En Sistemas: " + cliente.toString());
- pilaSiste.pop();
- }else{
- System.out.println("No Hay Clientes En La Pila Sistemas.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement