Correzione numeroContoCorrente
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package mybank;
|
package mybank;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,14 +18,21 @@ public class ContoCorrente {
|
|||||||
private Date dataDiNascita;
|
private Date dataDiNascita;
|
||||||
private double saldoIniziale;
|
private double saldoIniziale;
|
||||||
private int numeroContoCorrente;
|
private int numeroContoCorrente;
|
||||||
private static int numeroContoCorrenteGlobale;
|
|
||||||
|
|
||||||
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldoIniziale) {
|
private static ArrayList<Integer> numeriContiCorrenti = new ArrayList<>();
|
||||||
|
|
||||||
|
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldoIniziale,
|
||||||
|
int numeroContoCorrente) {
|
||||||
this.nome = nome;
|
this.nome = nome;
|
||||||
this.cognome = cognome;
|
this.cognome = cognome;
|
||||||
this.codiceFiscale = codiceFiscale;
|
this.codiceFiscale = codiceFiscale;
|
||||||
this.dataDiNascita = dataDiNascita;
|
this.dataDiNascita = dataDiNascita;
|
||||||
this.saldoIniziale = saldoIniziale;
|
this.saldoIniziale = saldoIniziale;
|
||||||
this.numeroContoCorrente = ++numeroContoCorrenteGlobale;
|
this.numeroContoCorrente = numeroContoCorrente;
|
||||||
|
numeriContiCorrenti.add(numeroContoCorrente);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Integer> getNumeriContiCorrenti() {
|
||||||
|
return numeriContiCorrenti;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,20 +101,34 @@ public class MyBank {
|
|||||||
String codiceFiscale;
|
String codiceFiscale;
|
||||||
Date dataDiNascita;
|
Date dataDiNascita;
|
||||||
double saldoIniziale;
|
double saldoIniziale;
|
||||||
|
int numeroContoCorrente;
|
||||||
|
boolean error;
|
||||||
|
|
||||||
System.out.print("Inserire il proprio nome: ");
|
do {
|
||||||
nome = sc.nextLine().trim();
|
error = false;
|
||||||
|
System.out.print("Inserire il proprio nome: ");
|
||||||
|
nome = sc.nextLine().trim();
|
||||||
|
|
||||||
System.out.print("Inserire il proprio cognome: ");
|
System.out.print("Inserire il proprio cognome: ");
|
||||||
cognome = sc.nextLine().trim();
|
cognome = sc.nextLine().trim();
|
||||||
|
|
||||||
codiceFiscale = codiceFiscale();
|
codiceFiscale = codiceFiscale();
|
||||||
|
|
||||||
dataDiNascita = dataDiNascita();
|
dataDiNascita = dataDiNascita();
|
||||||
|
|
||||||
saldoIniziale = saldoIniziale();
|
saldoIniziale = saldoIniziale();
|
||||||
|
|
||||||
conti.add(new ContoCorrente(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale));
|
numeroContoCorrente = codiceFiscale.hashCode();
|
||||||
|
|
||||||
|
if (ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
|
||||||
|
System.out.println("Errore: esiste già un conto corrente per questo codice fiscale, riprovare.");
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
conti.add(new ContoCorrente(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale, numeroContoCorrente));
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String codiceFiscale() {
|
static String codiceFiscale() {
|
||||||
|
|||||||
Reference in New Issue
Block a user