Gestione codice fiscale + numeroContoCorrente
This commit is contained in:
@@ -16,15 +16,16 @@ public class ContoCorrente {
|
|||||||
private double saldo;
|
private double saldo;
|
||||||
private int numeroContoCorrente;
|
private int numeroContoCorrente;
|
||||||
|
|
||||||
|
private static int totaleNumeriCorrenti;
|
||||||
private static ArrayList<Integer> numeriContiCorrenti = new ArrayList<>();
|
private static ArrayList<Integer> numeriContiCorrenti = new ArrayList<>();
|
||||||
|
|
||||||
public ContoCorrente() {
|
public ContoCorrente() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContoCorrente(Persona intestatario, double saldo, int numeroContoCorrente) {
|
public ContoCorrente(Persona intestatario, double saldo) {
|
||||||
this.intestatario = intestatario;
|
this.intestatario = intestatario;
|
||||||
this.saldo = saldo;
|
this.saldo = saldo;
|
||||||
this.numeroContoCorrente = numeroContoCorrente;
|
this.numeroContoCorrente = totaleNumeriCorrenti++;
|
||||||
numeriContiCorrenti.add(numeroContoCorrente);
|
numeriContiCorrenti.add(numeroContoCorrente);
|
||||||
MyBank.log("Apertura del conto con saldo iniziale di " + this.saldo, numeroContoCorrente);
|
MyBank.log("Apertura del conto con saldo iniziale di " + this.saldo, numeroContoCorrente);
|
||||||
}
|
}
|
||||||
@@ -41,6 +42,14 @@ public class ContoCorrente {
|
|||||||
return numeroContoCorrente;
|
return numeroContoCorrente;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Persona getIntestatario() {
|
||||||
|
return intestatario;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSaldo() {
|
||||||
|
return saldo;
|
||||||
|
}
|
||||||
|
|
||||||
public void versa(double quantita) {
|
public void versa(double quantita) {
|
||||||
this.saldo += quantita;
|
this.saldo += quantita;
|
||||||
MyBank.log("Versamento di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
MyBank.log("Versamento di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -132,10 +133,8 @@ public class MyBank {
|
|||||||
numeriContiCorrenti.add(conti.getLast().getNumeroContoCorrente());
|
numeriContiCorrenti.add(conti.getLast().getNumeroContoCorrente());
|
||||||
ContoCorrente.setNumeriContiCorrenti(numeriContiCorrenti);
|
ContoCorrente.setNumeriContiCorrenti(numeriContiCorrenti);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception _) {
|
||||||
System.out.println("Errore nella lettura del file di conto corrente.");
|
System.out.println("Errore nella lettura del file di conto corrente.");
|
||||||
System.out.println(e.getMessage());
|
|
||||||
System.out.println(e.getStackTrace());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,32 +143,35 @@ public class MyBank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
|
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
|
||||||
double saldoIniziale;
|
Persona persona;
|
||||||
int numeroContoCorrente;
|
|
||||||
Persona persona = persona();
|
|
||||||
boolean error;
|
boolean error;
|
||||||
ContoCorrente contoCorrente;
|
ContoCorrente contoCorrente;
|
||||||
|
List<String> listaCodiciFiscali;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
error = false;
|
error = false;
|
||||||
|
|
||||||
saldoIniziale = quantita("del saldo iniziale");
|
try {
|
||||||
|
persona = persona();
|
||||||
|
listaCodiciFiscali = ScriviLeggiFile.leggiCodiciFiscali();
|
||||||
|
|
||||||
numeroContoCorrente = Math.abs(persona.getCodiceFiscale().hashCode());
|
if (listaCodiciFiscali != null && listaCodiciFiscali.contains(persona.getCodiceFiscale())) {
|
||||||
|
System.out.println("Errore: esiste già un conto corrente per questo codice fiscale, riprovare.");
|
||||||
if (ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
|
pausa();
|
||||||
System.out.println("Errore: esiste già un conto corrente per questo codice fiscale, riprovare.");
|
error = true;
|
||||||
pausa();
|
} else {
|
||||||
error = true;
|
ScriviLeggiFile.salvaCodiceFiscale(persona.getCodiceFiscale());
|
||||||
} else {
|
File percorsoConti = new File(PATH_CONTI);
|
||||||
File percorsoConti = new File(PATH_CONTI);
|
if (!percorsoConti.exists()) {
|
||||||
if (!percorsoConti.exists()) {
|
percorsoConti.mkdir();
|
||||||
percorsoConti.mkdir();
|
}
|
||||||
|
contoCorrente = new ContoCorrente(persona, quantita("del saldo iniziale"));
|
||||||
|
conti.add(contoCorrente);
|
||||||
|
salvaContoCorrente(contoCorrente);
|
||||||
}
|
}
|
||||||
contoCorrente = new ContoCorrente(persona, saldoIniziale,
|
} catch (IOException e) {
|
||||||
numeroContoCorrente);
|
System.out.println(e.getMessage());
|
||||||
conti.add(contoCorrente);
|
error = true;
|
||||||
salvaContoCorrente(contoCorrente);
|
|
||||||
}
|
}
|
||||||
} while (error);
|
} while (error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
package mybank;
|
package mybank;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -15,16 +18,41 @@ public class Persona {
|
|||||||
private String nome;
|
private String nome;
|
||||||
private String cognome;
|
private String cognome;
|
||||||
private String codiceFiscale;
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
@JsonFormat
|
||||||
|
(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy",
|
||||||
|
timezone = "Europe/Rome")
|
||||||
private Date dataDiNascita;
|
private Date dataDiNascita;
|
||||||
|
|
||||||
|
private static ArrayList<String> codiciFiscali = new ArrayList<>();
|
||||||
|
|
||||||
|
public Persona(){}
|
||||||
|
|
||||||
public Persona(String nome, String cognome, String codiceFiscale, Date dataDiNascita) {
|
public Persona(String nome, String cognome, String codiceFiscale, Date dataDiNascita) {
|
||||||
this.nome = nome;
|
this.nome = nome;
|
||||||
this.cognome = cognome;
|
this.cognome = cognome;
|
||||||
this.codiceFiscale = codiceFiscale;
|
this.codiceFiscale = codiceFiscale;
|
||||||
this.dataDiNascita = dataDiNascita;
|
this.dataDiNascita = dataDiNascita;
|
||||||
|
codiciFiscali.add(codiceFiscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCodiceFiscale() {
|
public String getCodiceFiscale() {
|
||||||
return codiceFiscale;
|
return codiceFiscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getCodiciFiscali() {
|
||||||
|
return codiciFiscali;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCodiciFiscali(List<String> codiciFiscali) {
|
||||||
|
Persona.codiciFiscali = (ArrayList<String>) codiciFiscali;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNome() {
|
||||||
|
return nome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCognome() {
|
||||||
|
return cognome;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,46 @@
|
|||||||
*/
|
*/
|
||||||
package mybank;
|
package mybank;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Verde
|
* @author Verde
|
||||||
*/
|
*/
|
||||||
public class ScriviLeggiFile {
|
public class ScriviLeggiFile {
|
||||||
|
private static final String PATH_CODICI_FISCALI = "./src/mybank/codiciFiscali.txt";
|
||||||
|
|
||||||
|
private ScriviLeggiFile() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void salvaCodiceFiscale(String codiceFiscale) throws IOException {
|
||||||
|
try (BufferedWriter bw = new BufferedWriter(
|
||||||
|
new FileWriter(PATH_CODICI_FISCALI, true))) {
|
||||||
|
bw.write(codiceFiscale + "\n");
|
||||||
|
} catch (IOException _) {
|
||||||
|
throw new IOException("Errore nella scrittura del codice fiscale.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> leggiCodiciFiscali() throws IOException {
|
||||||
|
List<String> codiciFiscali = null;
|
||||||
|
|
||||||
|
File percorsoCodiciFiscali = new File(PATH_CODICI_FISCALI);
|
||||||
|
if (percorsoCodiciFiscali.exists()) {
|
||||||
|
try (BufferedReader bf = new BufferedReader(
|
||||||
|
new FileReader(PATH_CODICI_FISCALI))) {
|
||||||
|
codiciFiscali = bf.readAllLines();
|
||||||
|
} catch (IOException _) {
|
||||||
|
throw new IOException("Errore nella lettura dei codici fiscali.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return codiciFiscali;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user