Main
This commit is contained in:
parent
c7a3d14a32
commit
f24c58190e
@ -6,7 +6,7 @@ package appComune;
|
|||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import javax.swing.text.SimpleAttributeSet;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -30,11 +30,12 @@ public class Anagrafica {
|
|||||||
this.CF = GestisciCodiceFiscale.CalcolaCodiceFiscale(nome, cognome, dataNascita, luogo, sesso);
|
this.CF = GestisciCodiceFiscale.CalcolaCodiceFiscale(nome, cognome, dataNascita, luogo, sesso);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
SimpleDateFormat sdf = new SimpleDateFormat(MainComune.PATTERN_DATA);
|
||||||
String ritorno = "Nome: " + this.nome + "\nCognome: " + this.cognome + "\nData di nascita: "
|
String ritorno = "Nome: " + this.getNome() + "\nCognome: " + this.getCognome() + "\nData di nascita: "
|
||||||
+ sdf.parse(this.dataNascita) + "\nLuogo di nascita: " + this.luogoNascita + "\nSesso: " + this.sesso
|
+ sdf.format(this.getDataNascita()) + "\nLuogo di nascita: " + this.getLuogoNascita() + "\nSesso: " + this.getSesso()
|
||||||
+ "\nCodice fiscale: " + this.CF;
|
+ "\nCodice fiscale: " + this.getCF();
|
||||||
return ritorno;
|
return ritorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package appComune;
|
package appComune;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Verde
|
* @author Verde
|
||||||
|
|||||||
@ -4,6 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package appComune;
|
package appComune;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@ -13,9 +17,12 @@ import java.util.Scanner;
|
|||||||
*/
|
*/
|
||||||
public class MainComune {
|
public class MainComune {
|
||||||
static Scanner sc = new Scanner(System.in);
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
static final String PATTERN_DATA = "dd/MM/yy";
|
||||||
|
static final String[] sessiAmmessi = { "m", "f" };
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int scelta = -1;
|
int scelta = -1;
|
||||||
|
ArrayList<Anagrafica> cittadini = new ArrayList<>();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
System.out.println("Scegliere un'opzione:");
|
System.out.println("Scegliere un'opzione:");
|
||||||
@ -32,11 +39,11 @@ public class MainComune {
|
|||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
aggiungiCittatino(cittadini);
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
stampaCittadini(cittadini);
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -56,4 +63,106 @@ public class MainComune {
|
|||||||
sc.nextLine();
|
sc.nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void aggiungiCittatino(ArrayList<Anagrafica> cittadini) {
|
||||||
|
String nome;
|
||||||
|
String cognome;
|
||||||
|
Date dataNascita;
|
||||||
|
String luogoNascita;
|
||||||
|
String sesso;
|
||||||
|
|
||||||
|
System.out.print("Inserire il nome, compresi eventuali secondi nomi: ");
|
||||||
|
nome = sc.nextLine().trim();
|
||||||
|
|
||||||
|
System.out.print("Inserire il cognome, compresi eventuali secondi cognomi: ");
|
||||||
|
cognome = sc.nextLine().trim();
|
||||||
|
|
||||||
|
dataNascita = dataNascita();
|
||||||
|
|
||||||
|
luogoNascita = luogoNascita();
|
||||||
|
|
||||||
|
sesso = sesso();
|
||||||
|
|
||||||
|
cittadini.add(new Anagrafica(nome, cognome, dataNascita, luogoNascita, sesso));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static Date dataNascita() {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_DATA);
|
||||||
|
Date ritorno = null;
|
||||||
|
boolean error;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.print("Inserire la data di nascita nel formato gg/mm/aa: ");
|
||||||
|
ritorno = sdf.parse(sc.nextLine().trim());
|
||||||
|
} catch (ParseException _) {
|
||||||
|
System.out.println("Errore nella lettura della data di nascita.");
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String luogoNascita() {
|
||||||
|
String ritorno = null;
|
||||||
|
boolean error;
|
||||||
|
final String COMUNE = "varese";
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
|
||||||
|
System.out.print("Inserire il comune di nascita: ");
|
||||||
|
ritorno = sc.nextLine().toLowerCase().trim();
|
||||||
|
|
||||||
|
if (!ritorno.equals(COMUNE)) {
|
||||||
|
System.out.println("Errore: è consentito esclusivamente il comune di " + COMUNE);
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String sesso() {
|
||||||
|
String ritorno = null;
|
||||||
|
boolean error;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
|
||||||
|
System.out.println("Inserire il sesso tra le seguenti opzioni: ");
|
||||||
|
for (String sesso : sessiAmmessi) {
|
||||||
|
System.out.println(sesso);
|
||||||
|
}
|
||||||
|
System.out.print("Scelta: ");
|
||||||
|
ritorno = sc.nextLine().toLowerCase().trim();
|
||||||
|
|
||||||
|
for (int i = 0; i < sessiAmmessi.length && !exit; i++) {
|
||||||
|
exit = ritorno.equals(sessiAmmessi[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exit) {
|
||||||
|
System.out.println("Errore: il sesso può essere solo una di queste opzioni:");
|
||||||
|
for (String sesso : sessiAmmessi) {
|
||||||
|
System.out.println(sesso);
|
||||||
|
}
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stampaCittadini(ArrayList<Anagrafica> cittadini) {
|
||||||
|
for (Anagrafica cittadino : cittadini) {
|
||||||
|
System.out.println(cittadino.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user