Creazione persona
This commit is contained in:
@@ -5,68 +5,54 @@
|
||||
package mybank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
*/
|
||||
public class ContoCorrente {
|
||||
private String nome;
|
||||
private String cognome;
|
||||
private String codiceFiscale;
|
||||
private Persona intestatario;
|
||||
private double saldo;
|
||||
private int numeroContoCorrente;
|
||||
|
||||
private static ArrayList<Integer> numeriContiCorrenti = new ArrayList<>();
|
||||
|
||||
@JsonFormat
|
||||
(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
|
||||
private Date dataDiNascita;
|
||||
|
||||
public ContoCorrente() {
|
||||
}
|
||||
|
||||
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldo,
|
||||
int numeroContoCorrente) {
|
||||
this.nome = nome;
|
||||
this.cognome = cognome;
|
||||
this.codiceFiscale = codiceFiscale;
|
||||
this.dataDiNascita = dataDiNascita;
|
||||
public ContoCorrente(Persona intestatario, double saldo, int numeroContoCorrente) {
|
||||
this.intestatario = intestatario;
|
||||
this.saldo = saldo;
|
||||
this.numeroContoCorrente = numeroContoCorrente;
|
||||
numeriContiCorrenti.add(numeroContoCorrente);
|
||||
MyBank.log("Apertura del conto con saldo iniziale di " + this.saldo, numeroContoCorrente);
|
||||
}
|
||||
|
||||
|
||||
public static List<Integer> getNumeriContiCorrenti() {
|
||||
return numeriContiCorrenti;
|
||||
}
|
||||
|
||||
public static void setNumeriContiCorrenti(List<Integer> numeriContiCorrenti) {
|
||||
ContoCorrente.numeriContiCorrenti = (ArrayList<Integer>)numeriContiCorrenti;
|
||||
ContoCorrente.numeriContiCorrenti = (ArrayList<Integer>) numeriContiCorrenti;
|
||||
}
|
||||
|
||||
public int getNumeroContoCorrente() {
|
||||
return numeroContoCorrente;
|
||||
}
|
||||
|
||||
public void versa(double quantita){
|
||||
public void versa(double quantita) {
|
||||
this.saldo += quantita;
|
||||
MyBank.log("Versamento di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
||||
logSaldoCorrente();
|
||||
}
|
||||
|
||||
public void preleva(double quantita) throws IllegalArgumentException{
|
||||
|
||||
public void preleva(double quantita) throws IllegalArgumentException {
|
||||
if (quantita > this.saldo) {
|
||||
MyBank.log("Tentato prelievo di " + quantita + " fallito per superamento saldo.", this.numeroContoCorrente);
|
||||
logSaldoCorrente();
|
||||
throw new IllegalArgumentException("La quantità desiderata eccede il saldo corrente.");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.saldo -= quantita;
|
||||
MyBank.log("Prelievo di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
||||
logSaldoCorrente();
|
||||
@@ -76,23 +62,4 @@ public class ContoCorrente {
|
||||
private void logSaldoCorrente() {
|
||||
MyBank.log("Saldo corrente: " + this.saldo + "\n", this.numeroContoCorrente);
|
||||
}
|
||||
public String getNome() {
|
||||
return nome;
|
||||
}
|
||||
|
||||
public String getCognome() {
|
||||
return cognome;
|
||||
}
|
||||
|
||||
public String getCodiceFiscale() {
|
||||
return codiceFiscale;
|
||||
}
|
||||
|
||||
public Date getDataDiNascita() {
|
||||
return dataDiNascita;
|
||||
}
|
||||
|
||||
public double getSaldo() {
|
||||
return saldo;
|
||||
}
|
||||
}
|
||||
@@ -144,30 +144,18 @@ public class MyBank {
|
||||
}
|
||||
|
||||
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
|
||||
String nome;
|
||||
String cognome;
|
||||
String codiceFiscale;
|
||||
Date dataDiNascita;
|
||||
double saldoIniziale;
|
||||
int numeroContoCorrente;
|
||||
Persona persona = persona();
|
||||
boolean error;
|
||||
ContoCorrente contoCorrente;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("Inserire il proprio nome: ");
|
||||
nome = sc.nextLine().trim();
|
||||
|
||||
System.out.print("Inserire il proprio cognome: ");
|
||||
cognome = sc.nextLine().trim();
|
||||
|
||||
codiceFiscale = codiceFiscale();
|
||||
|
||||
dataDiNascita = dataDiNascita();
|
||||
|
||||
saldoIniziale = quantita("del saldo iniziale");
|
||||
|
||||
numeroContoCorrente = Math.abs(codiceFiscale.hashCode());
|
||||
numeroContoCorrente = Math.abs(persona.getCodiceFiscale().hashCode());
|
||||
|
||||
if (ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
|
||||
System.out.println("Errore: esiste già un conto corrente per questo codice fiscale, riprovare.");
|
||||
@@ -178,7 +166,7 @@ public class MyBank {
|
||||
if (!percorsoConti.exists()) {
|
||||
percorsoConti.mkdir();
|
||||
}
|
||||
contoCorrente = new ContoCorrente(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale,
|
||||
contoCorrente = new ContoCorrente(persona, saldoIniziale,
|
||||
numeroContoCorrente);
|
||||
conti.add(contoCorrente);
|
||||
salvaContoCorrente(contoCorrente);
|
||||
@@ -186,6 +174,25 @@ public class MyBank {
|
||||
} while (error);
|
||||
}
|
||||
|
||||
static Persona persona() {
|
||||
String nome;
|
||||
String cognome;
|
||||
String codiceFiscale;
|
||||
Date dataDiNascita;
|
||||
|
||||
System.out.print("Inserire il proprio nome: ");
|
||||
nome = sc.nextLine().trim();
|
||||
|
||||
System.out.print("Inserire il proprio cognome: ");
|
||||
cognome = sc.nextLine().trim();
|
||||
|
||||
codiceFiscale = codiceFiscale();
|
||||
|
||||
dataDiNascita = dataDiNascita();
|
||||
|
||||
return new Persona(nome, cognome, codiceFiscale, dataDiNascita);
|
||||
}
|
||||
|
||||
static String codiceFiscale() {
|
||||
String codiceFiscale;
|
||||
boolean error;
|
||||
|
||||
@@ -4,10 +4,27 @@
|
||||
*/
|
||||
package mybank;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
*/
|
||||
public class Persona {
|
||||
|
||||
private String nome;
|
||||
private String cognome;
|
||||
private String codiceFiscale;
|
||||
private Date dataDiNascita;
|
||||
|
||||
public Persona(String nome, String cognome, String codiceFiscale, Date dataDiNascita) {
|
||||
this.nome = nome;
|
||||
this.cognome = cognome;
|
||||
this.codiceFiscale = codiceFiscale;
|
||||
this.dataDiNascita = dataDiNascita;
|
||||
}
|
||||
|
||||
public String getCodiceFiscale() {
|
||||
return codiceFiscale;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user