Mostra operazioni

This commit is contained in:
La Programmatrice Verde
2026-03-03 11:37:42 +01:00
parent 5504dfd91c
commit d6f140dae7
11 changed files with 47 additions and 49 deletions

View File

@@ -4,7 +4,9 @@
*/
package logic;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -35,7 +37,7 @@ public class ContoCorrente {
}
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldo,
int numeroContoCorrente) {
int numeroContoCorrente) throws IOException{
this.nome = nome;
this.cognome = cognome;
this.codiceFiscale = codiceFiscale;
@@ -58,13 +60,13 @@ public class ContoCorrente {
return numeroContoCorrente;
}
public void versa(double quantita){
public void versa(double quantita) throws IOException{
this.saldo += quantita;
log("Versamento di " + quantita + " effettuato con successo.");
logSaldoCorrente();
}
public void preleva(double quantita) throws IllegalArgumentException{
public void preleva(double quantita) throws IllegalArgumentException, IOException{
if (quantita > this.saldo) {
log("Tentato prelievo di " + quantita + " fallito per superamento saldo.");
logSaldoCorrente();
@@ -77,11 +79,11 @@ public class ContoCorrente {
}
}
private void logSaldoCorrente() {
private void logSaldoCorrente() throws IOException{
log("Saldo corrente: " + this.saldo + "\n");
}
private void log(String messaggio) {
private void log(String messaggio) throws IOException{
StringBuilder sb = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.sss dd/MM/yyyy");
try (BufferedWriter bw = new BufferedWriter(
@@ -94,7 +96,16 @@ public class ContoCorrente {
bw.write(sb.toString());
} catch (IOException _) {
System.out.println("Errore nella scrittura del movimento.");
throw new IOException("Errore nella scrittura del movimento.");
}
}
public String getLog() throws IOException{
try (BufferedReader br = new BufferedReader(
new FileReader(MyBank.PATH_CONTI + "movimenti_" + this.numeroContoCorrente + ".txt"))) {
return br.readAllAsString();
} catch (IOException _) {
throw new IOException("Errore nella lettura dei movimenti.");
}
}