Merge
This commit is contained in:
98
src/logic/ContoCorrente.java
Normal file
98
src/logic/ContoCorrente.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
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 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;
|
||||
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;
|
||||
}
|
||||
|
||||
public int getNumeroContoCorrente() {
|
||||
return numeroContoCorrente;
|
||||
}
|
||||
|
||||
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{
|
||||
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 {
|
||||
this.saldo -= quantita;
|
||||
MyBank.log("Prelievo di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
||||
logSaldoCorrente();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user