Opzione 1
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
*/
|
||||
package mybank;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
@@ -18,13 +22,15 @@ public class MyBank {
|
||||
*/
|
||||
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
||||
|
||||
public static void main(String[] args) {
|
||||
int scelta = -1;
|
||||
ArrayList<ContoCorrente> conti = new ArrayList<>();
|
||||
|
||||
do {
|
||||
System.out.println("Scegliere un'opzione:");
|
||||
System.out.println("1. ");
|
||||
System.out.println("1. Aggiungi conto corrente");
|
||||
System.out.println("2. ");
|
||||
System.out.println("3. ");
|
||||
System.out.println("0. Esci");
|
||||
@@ -38,15 +44,24 @@ public class MyBank {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
|
||||
aggiungiConto(conti);
|
||||
System.out.println("Conto corrente aggiunto con successo.");
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
|
||||
if(conti.isEmpty()){
|
||||
System.out.println("Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.");
|
||||
}else{
|
||||
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 3:
|
||||
|
||||
if(conti.isEmpty()){
|
||||
System.out.println("Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.");
|
||||
}else{
|
||||
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
default:
|
||||
@@ -54,8 +69,7 @@ public class MyBank {
|
||||
pausa();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (InputMismatchException _) {
|
||||
} catch (InputMismatchException _) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
}
|
||||
@@ -66,4 +80,73 @@ public class MyBank {
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
sc.nextLine();
|
||||
}
|
||||
|
||||
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
|
||||
String nome;
|
||||
String cognome;
|
||||
String codiceFiscale;
|
||||
Date dataDiNascita;
|
||||
double saldoIniziale;
|
||||
|
||||
System.out.print("Inserire il proprio nome: ");
|
||||
nome = sc.nextLine().trim();
|
||||
|
||||
System.out.print("Inserire il proprio cognome: ");
|
||||
cognome = sc.nextLine().trim();
|
||||
|
||||
// TODO: codiceFiscale da prendere da vecchio programma
|
||||
codiceFiscale = "XDKEKW";
|
||||
|
||||
dataDiNascita = dataDiNascita();
|
||||
|
||||
saldoIniziale = saldoIniziale();
|
||||
|
||||
conti.add(new ContoCorrente(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale));
|
||||
}
|
||||
|
||||
static Date dataDiNascita() {
|
||||
Date dataDiNascita = null;
|
||||
boolean error;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
sdf.setLenient(false);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("Inserire la propria data di nascita: ");
|
||||
try {
|
||||
dataDiNascita = sdf.parse(sc.nextLine());
|
||||
} catch (ParseException _) {
|
||||
System.out.println("Errore: la data inserita non è valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
return dataDiNascita;
|
||||
}
|
||||
|
||||
static double saldoIniziale() {
|
||||
double saldoIniziale = 0;
|
||||
boolean error;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("Inserire il saldo iniziale: ");
|
||||
try {
|
||||
saldoIniziale = sc.nextDouble();
|
||||
sc.nextLine();
|
||||
|
||||
if (saldoIniziale <= 0) {
|
||||
System.out.println("Errore: il saldo iniziale non può essere minore o uguale a zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException _) {
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
return saldoIniziale;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user