aggiungiDipendente

This commit is contained in:
La Programmatrice Verde
2026-03-19 21:42:02 +01:00
parent 5c174b7581
commit 2bab2fc663
2 changed files with 41 additions and 4 deletions

View File

@@ -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;
}
}