Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void cargarCliente() {
- Scanner tecl=new Scanner(System.in);
- try {
- do{
- System.out.println("Dame tu DNI: ");
- this.DNI=tecl.next();
- }while(!valida(this.DNI));
- } catch (Exception e) {
- do{
- System.out.println("Has introducido mal tu DNI, hazlo de nuevo: ");
- this.DNI=tecl.next();
- }while(!valida(this.DNI));
- }
- System.out.println("Dame tu nombre: ");
- this.nombre=tecl.next();
- System.out.println("Dame tus apellidos: ");
- this.apellidos=tecl.next();
- System.out.println("Dame tu edad: ");
- this.edad=tecl.nextInt();
- System.out.println("Dame tu direccion");
- this.direccion=tecl.next();
- System.out.println("Dame tu email: ");
- this.email=tecl.next();
- System.out.println("Dame tu hora de llegada: ");
- this.hora_llegada=tecl.nextInt();
- System.out.println("Dame los dias de estancia: ");
- this.dias_dist=tecl.nextInt();
- }
- public void añadirVehiculo() {
- Scanner tecl=new Scanner(System.in);
- System.out.println("Dime que vehiculo quieres añadir: C/M/F");
- String v=tecl.nextLine();
- switch (v) {
- case "c":
- Coche c = new Coche();
- do{
- System.out.println("Dime la matricula: ");
- c.setMatricula(tecl.next());
- }while(!c.valida(c.getMatricula()));
- System.out.println("Dime la marca: ");
- c.setMarca(tecl.next());
- System.out.println("Dime la color: ");
- c.setColor(tecl.next());
- System.out.println("Dime el modelo: ");
- c.setModelo(tecl.next());
- System.out.println("Dime el numero de puertas: ");
- c.setNum_puertas(tecl.nextInt());
- vehiculo.add(c);
- break;
- case "m":
- Moto m = new Moto();
- System.out.println("Dime la matricula: ");
- m.setMatricula(tecl.next());
- System.out.println("Dime la marca: ");
- m.setMarca(tecl.next());
- System.out.println("Dime la color: ");
- m.setColor(tecl.next());
- System.out.println("Dime el modelo: ");
- m.setModelo(tecl.next());
- System.out.println("Dime el tipo: ");
- m.setTipo(tecl.next());
- System.out.println("Dime la cilindrada: ");
- m.setCilindrada(tecl.nextInt());
- System.out.println("Dime el carne: ");
- m.setCarnet(tecl.next());
- m.setTipo_vehiculo("moto");
- break;
- case "f":
- Furgoneta f = new Furgoneta();
- System.out.println("Dime la matricula: ");
- f.setMatricula(tecl.next());
- System.out.println("Dime la marca: ");
- f.setMarca(tecl.next());
- System.out.println("Dime la color: ");
- f.setColor(tecl.next());
- System.out.println("Dime el modelo: ");
- f.setModelo(tecl.next());
- System.out.println("Dime la capacidad: ");
- f.setcapacidad(tecl.nextInt());
- vehiculo.add(f);
- break;
- }
- }
- @Override
- public String toString() {
- return "Cliente " + " con DNI: " + DNI + ", nombre: " + nombre + ", apellidos: " + apellidos
- + ", direccion: " + direccion + "\t" + vehiculo.toString();
- }
- @Override
- public boolean valida(String cadena) {
- // Array con las letras posibles del dni en su posición
- char[] letraDni = {
- 'T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'
- };
- String num= "";
- int ind = 0;
- boolean valido;
- if(this.DNI.length() == 8) {
- this.DNI = "0" + this.DNI;
- }
- if (!Character.isLetter(this.DNI.charAt(8))) {
- return false;
- }
- if (this.DNI.length() != 9){
- return false;
- }
- for (int i=0; i<8; i++) {
- if(!Character.isDigit(this.DNI.charAt(i))){
- return false;
- }
- num += this.DNI.charAt(i);
- }
- ind = Integer.parseInt(num);
- ind %= 23;
- if ((Character.toUpperCase(this.DNI.charAt(8))) != letraDni[ind]){
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement