aggiungiDipendente
This commit is contained in:
@@ -7,6 +7,7 @@ package gestioneferie;
|
||||
import java.util.ArrayList;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,7 +45,8 @@ public class GestioneFerie {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
|
||||
aggiungiDipendente(dipendenti);
|
||||
System.out.println("Dipendente aggiunto con successo.");
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
@@ -79,4 +81,40 @@ public class GestioneFerie {
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
sc.nextLine();
|
||||
}
|
||||
|
||||
private static void aggiungiDipendente(ArrayList<Dipendente> dipendenti) {
|
||||
String nome;
|
||||
String cognome;
|
||||
String codiceFiscale;
|
||||
|
||||
System.out.print("Inserire il nome del dipendente: ");
|
||||
nome = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
System.out.print("Inserire il cognome del dipendente: ");
|
||||
cognome = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
codiceFiscale = codiceFiscale();
|
||||
|
||||
dipendenti.add(new Dipendente(codiceFiscale, nome, cognome));
|
||||
}
|
||||
|
||||
public static String codiceFiscale() {
|
||||
String codiceFiscale;
|
||||
Pattern pattern = Pattern.compile("[A-Z]{6}[ABCDEHLMPRST]{3}\\d{2}[A-Z]\\d{3}[A-Z]");
|
||||
boolean error;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("Inserire il codice fiscale: ");
|
||||
codiceFiscale = sc.nextLine();
|
||||
|
||||
if (pattern.matcher(codiceFiscale).find()) {
|
||||
System.out.print(ERRORE_GENERICO);
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
return codiceFiscale;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user