diff --git a/build/classes/gui/GUIMyBank$1.class b/build/classes/gui/GUIMyBank$1.class
index 4765437..18b9df5 100644
Binary files a/build/classes/gui/GUIMyBank$1.class and b/build/classes/gui/GUIMyBank$1.class differ
diff --git a/build/classes/gui/GUIMyBank$2.class b/build/classes/gui/GUIMyBank$2.class
index cd0505a..d64bcbe 100644
Binary files a/build/classes/gui/GUIMyBank$2.class and b/build/classes/gui/GUIMyBank$2.class differ
diff --git a/build/classes/gui/GUIMyBank$3.class b/build/classes/gui/GUIMyBank$3.class
index 0e82a8c..b6a0958 100644
Binary files a/build/classes/gui/GUIMyBank$3.class and b/build/classes/gui/GUIMyBank$3.class differ
diff --git a/build/classes/gui/GUIMyBank$4.class b/build/classes/gui/GUIMyBank$4.class
index 160d6b1..0d66f7f 100644
Binary files a/build/classes/gui/GUIMyBank$4.class and b/build/classes/gui/GUIMyBank$4.class differ
diff --git a/build/classes/gui/GUIMyBank$5.class b/build/classes/gui/GUIMyBank$5.class
index fa65b26..e4e0ad8 100644
Binary files a/build/classes/gui/GUIMyBank$5.class and b/build/classes/gui/GUIMyBank$5.class differ
diff --git a/build/classes/gui/GUIMyBank$6.class b/build/classes/gui/GUIMyBank$6.class
new file mode 100644
index 0000000..9d28982
Binary files /dev/null and b/build/classes/gui/GUIMyBank$6.class differ
diff --git a/build/classes/gui/GUIMyBank.class b/build/classes/gui/GUIMyBank.class
index c116f6a..85d8fd6 100644
Binary files a/build/classes/gui/GUIMyBank.class and b/build/classes/gui/GUIMyBank.class differ
diff --git a/build/classes/gui/GUIMyBank.form b/build/classes/gui/GUIMyBank.form
index 40771b4..bba498e 100644
--- a/build/classes/gui/GUIMyBank.form
+++ b/build/classes/gui/GUIMyBank.form
@@ -26,7 +26,9 @@
-
+
+
+
@@ -60,7 +62,7 @@
-
+
@@ -120,7 +122,10 @@
-
+
+
+
+
@@ -238,5 +243,13 @@
+
+
+
+
+
+
+
+
diff --git a/build/classes/logic/ContoCorrente.class b/build/classes/logic/ContoCorrente.class
index e179b8b..86eaf68 100644
Binary files a/build/classes/logic/ContoCorrente.class and b/build/classes/logic/ContoCorrente.class differ
diff --git a/build/classes/logic/MyBank.class b/build/classes/logic/MyBank.class
index eff9398..637d1d1 100644
Binary files a/build/classes/logic/MyBank.class and b/build/classes/logic/MyBank.class differ
diff --git a/build/classes/logic/conti/conto_692979128.json b/build/classes/logic/conti/conto_692979128.json
deleted file mode 100644
index 75ff43f..0000000
--- a/build/classes/logic/conti/conto_692979128.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "nome" : "Verde",
- "cognome" : "Bassanetti",
- "codiceFiscale" : "AAAAAA12A123Z",
- "saldo" : 200.0,
- "numeroContoCorrente" : 692979128,
- "dataDiNascita" : "04/07/2008"
-}
\ No newline at end of file
diff --git a/build/classes/logic/conti/movimenti_692979128.txt b/build/classes/logic/conti/movimenti_692979128.txt
deleted file mode 100644
index ceafdde..0000000
--- a/build/classes/logic/conti/movimenti_692979128.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-[12:04:00.000 03/03/2026] Apertura del conto con saldo iniziale di 200.0
-[12:04:02.002 03/03/2026] Versamento di 5000.0 effettuato con successo.
-[12:04:02.002 03/03/2026] Saldo corrente: 5200.0
-[12:04:05.005 03/03/2026] Prelievo di 20.0 effettuato con successo.
-[12:04:05.005 03/03/2026] Saldo corrente: 5180.0
-[16:33:26.026 03/03/2026] Versamento di 2.0E11 effettuato con successo.
-[16:33:26.026 03/03/2026] Saldo corrente: 2.000000002E11
-[16:33:48.048 03/03/2026] Prelievo di 2.0E10 effettuato con successo.
-[16:33:48.048 03/03/2026] Saldo corrente: 1.800000002E11
-[16:33:57.057 03/03/2026] Tentato prelievo di 2.0E11 fallito per superamento saldo.
-[16:33:57.057 03/03/2026] Saldo corrente: 1.800000002E11
-[16:34:00.000 03/03/2026] Prelievo di 2000000.0 effettuato con successo.
-[16:34:00.000 03/03/2026] Saldo corrente: 1.799980002E11
-[16:34:05.005 03/03/2026] Tentato prelievo di 2.0E11 fallito per superamento saldo.
-[16:34:05.005 03/03/2026] Saldo corrente: 1.799980002E11
-[16:34:08.008 03/03/2026] Prelievo di 9.9999999E7 effettuato con successo.
-[16:34:08.008 03/03/2026] Saldo corrente: 1.79898000201E11
-[16:34:13.013 03/03/2026] Prelievo di 9.99999999E8 effettuato con successo.
-[16:34:13.013 03/03/2026] Saldo corrente: 1.78898000202E11
-[16:34:17.017 03/03/2026] Prelievo di 9.999999999E9 effettuato con successo.
-[16:34:17.017 03/03/2026] Saldo corrente: 1.68898000203E11
-[16:34:21.021 03/03/2026] Tentato prelievo di 1.0E17 fallito per superamento saldo.
-[16:34:21.021 03/03/2026] Saldo corrente: 1.68898000203E11
-[16:34:23.023 03/03/2026] Tentato prelievo di 9.999999999999E12 fallito per superamento saldo.
-[16:34:23.023 03/03/2026] Saldo corrente: 1.68898000203E11
-[16:34:25.025 03/03/2026] Prelievo di 9.99999999E8 effettuato con successo.
-[16:34:25.025 03/03/2026] Saldo corrente: 1.67898000204E11
-[16:34:29.029 03/03/2026] Prelievo di 9.999999999E9 effettuato con successo.
-[16:34:29.029 03/03/2026] Saldo corrente: 1.57898000205E11
-[16:34:37.037 03/03/2026] Prelievo di 1.0E11 effettuato con successo.
-[16:34:37.037 03/03/2026] Saldo corrente: 5.7898000205E10
-[16:34:43.043 03/03/2026] Prelievo di 5.0E10 effettuato con successo.
-[16:34:43.043 03/03/2026] Saldo corrente: 7.898000205E9
-[16:34:47.047 03/03/2026] Prelievo di 7.0E9 effettuato con successo.
-[16:34:47.047 03/03/2026] Saldo corrente: 8.98000205E8
-[16:34:50.050 03/03/2026] Prelievo di 8.0E8 effettuato con successo.
-[16:34:50.050 03/03/2026] Saldo corrente: 9.8000205E7
-[16:34:53.053 03/03/2026] Prelievo di 9.0E7 effettuato con successo.
-[16:34:53.053 03/03/2026] Saldo corrente: 8000205.0
diff --git a/src/gui/GUIMyBank.form b/src/gui/GUIMyBank.form
index 40771b4..bba498e 100644
--- a/src/gui/GUIMyBank.form
+++ b/src/gui/GUIMyBank.form
@@ -26,7 +26,9 @@
-
+
+
+
@@ -60,7 +62,7 @@
-
+
@@ -120,7 +122,10 @@
-
+
+
+
+
@@ -238,5 +243,13 @@
+
+
+
+
+
+
+
+
diff --git a/src/gui/GUIMyBank.java b/src/gui/GUIMyBank.java
index 2c69ce1..69543ae 100644
--- a/src/gui/GUIMyBank.java
+++ b/src/gui/GUIMyBank.java
@@ -7,7 +7,6 @@ package gui;
import java.awt.Color;
import java.io.IOException;
import java.text.ParseException;
-import java.util.ArrayList;
import java.util.Date;
import logic.MyBank;
import logic.ContoCorrente;
@@ -36,10 +35,10 @@ public class GUIMyBank extends javax.swing.JFrame {
public GUIMyBank() {
initComponents();
try {
- ArrayList conti = (ArrayList) MyBank.importaConti();
- MyBank.setConti(conti);
+ MyBank.importaConti();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
+ System.exit(3);
}
lblNumeroContoCorrente.setVisible(false);
txtNumeroContoCorrente.setVisible(false);
@@ -49,6 +48,14 @@ public class GUIMyBank extends javax.swing.JFrame {
btnListaMovimenti.setVisible(false);
txtaListaMovimenti.setVisible(false);
txtaListaMovimenti.setEditable(false);
+ btnChiudereContoCorrente.setVisible(false);
+
+ addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
+ public void windowClosing(java.awt.event.WindowEvent e) {
+ salva(true);
+ }
+ });
}
/**
@@ -62,6 +69,7 @@ public class GUIMyBank extends javax.swing.JFrame {
// //GEN-BEGIN:initComponents
private void initComponents() {
@@ -84,6 +92,7 @@ public class GUIMyBank extends javax.swing.JFrame {
txtaListaMovimenti = new javax.swing.JTextArea();
lblNumeroContoCorrente = new javax.swing.JLabel();
txtNumeroContoCorrente = new javax.swing.JTextField();
+ btnChiudereContoCorrente = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@@ -147,6 +156,9 @@ public class GUIMyBank extends javax.swing.JFrame {
lblNumeroContoCorrente.setText("Numero conto corrente:");
+ btnChiudereContoCorrente.setText("Chiudere conto corrente");
+ btnChiudereContoCorrente.addActionListener(this::btnChiudereContoCorrenteActionPerformed);
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@@ -154,7 +166,9 @@ public class GUIMyBank extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup()
.addGap(99, 99, 99)
.addComponent(btnAprireContoCorrente)
- .addContainerGap(187, Short.MAX_VALUE))
+ .addGap(18, 18, 18)
+ .addComponent(btnChiudereContoCorrente)
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -194,8 +208,8 @@ public class GUIMyBank extends javax.swing.JFrame {
.addComponent(txtCognome,
javax.swing.GroupLayout.PREFERRED_SIZE, 113,
javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39,
- Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
+ javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblNumeroContoCorrente, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@@ -261,7 +275,9 @@ public class GUIMyBank extends javax.swing.JFrame {
.addGap(18, 18, 18)
.addComponent(btnListaMovimenti)))
.addGap(18, 18, 18)
- .addComponent(btnAprireContoCorrente)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(btnAprireContoCorrente)
+ .addComponent(btnChiudereContoCorrente))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1)
.addGap(14, 14, 14)));
@@ -269,13 +285,63 @@ public class GUIMyBank extends javax.swing.JFrame {
pack();
}// //GEN-END:initComponents
- private void btnListaMovimentiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnListaMovimentiActionPerformed
- try {
- txtaListaMovimenti.setText(contoCorrenteAperto.getLog());
- txtaListaMovimenti.setVisible(true);
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
+ private void btnChiudereContoCorrenteActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnChiudereContoCorrenteActionPerformed
+ salva(false);
+ lblNumeroContoCorrente.setVisible(false);
+ txtNumeroContoCorrente.setVisible(false);
+ btnVersamento.setVisible(false);
+ btnPrelievo.setVisible(false);
+ btnListaMovimenti.setVisible(false);
+ txtNome.setEditable(true);
+ txtCognome.setEditable(true);
+ txtCodiceFiscale.setEditable(true);
+ txtDataDiNascita.setEditable(true);
+ txtSaldoIniziale.setEditable(true);
+ btnAprireContoCorrente.setEnabled(true);
+ btnDataDiNascita.setEnabled(true);
+ btnChiudereContoCorrente.setVisible(false);
+ txtaListaMovimenti.setVisible(false);
+ lblSaldoIniziale.setText("Saldo iniziale");
+ txtNome.setText("");
+ txtCognome.setText("");
+ txtCodiceFiscale.setText("");
+ txtDataDiNascita.setText("");
+ txtSaldoIniziale.setText("");
+ }// GEN-LAST:event_btnChiudereContoCorrenteActionPerformed
+
+ private void salva(boolean isProgramQuitting) {
+ String messaggioSalvataggio = isProgramQuitting ? "Conti correnti salvati correttamente."
+ : "Conto corrente salvato correttamente.";
+ switch (JOptionPane.showConfirmDialog(null, "Salvare?", "Esci", JOptionPane.YES_NO_OPTION)) {
+ case 0:
+ try {
+ if (isProgramQuitting) {
+ MyBank.salvaContiCorrenti();
+ } else {
+ MyBank.salvaContoCorrente(contoCorrenteAperto);
+ }
+ JOptionPane.showMessageDialog(null, messaggioSalvataggio);
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(null, e.getMessage());
+ }
+ break;
+ case 1:
+ if (!isProgramQuitting) {
+ try {
+ MyBank.annullaUltimoContoCorrente();
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(null, e.getMessage());
+ }
+ }
+ break;
+ default:
+ break;
}
+ }
+
+ private void btnListaMovimentiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnListaMovimentiActionPerformed
+ txtaListaMovimenti.setText(contoCorrenteAperto.getLogAsString());
+ txtaListaMovimenti.setVisible(true);
}// GEN-LAST:event_btnListaMovimentiActionPerformed
private void txtNomeFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_txtNomeFocusGained
@@ -313,8 +379,6 @@ public class GUIMyBank extends javax.swing.JFrame {
} catch (NumberFormatException _) {
JOptionPane.showMessageDialog(null, "L'importo che si desidera versare non è valido.");
error = true;
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
}
} while (error);
}// GEN-LAST:event_btnVersamentoActionPerformed
@@ -337,8 +401,6 @@ public class GUIMyBank extends javax.swing.JFrame {
} catch (IllegalArgumentException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
error = true;
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
}
} while (error);
}// GEN-LAST:event_btnPrelievoActionPerformed
@@ -399,13 +461,13 @@ public class GUIMyBank extends javax.swing.JFrame {
return;
}
- try {
- ContoCorrenteWrapper conto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita,
+ ContoCorrenteWrapper conto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita,
saldoIniziale);
contoCorrenteAperto = conto.getConto();
if (conto.isImported()) {
- JOptionPane.showMessageDialog(null, "Esiste già un conto corrente per il codice fiscale specificato.\nVerrà aperto il conto corrente esistente.");
+ JOptionPane.showMessageDialog(null,
+ "Esiste già un conto corrente per il codice fiscale specificato.\nVerrà aperto il conto corrente esistente.");
txtNome.setText(contoCorrenteAperto.getNome());
txtCognome.setText(contoCorrenteAperto.getCognome());
txtCodiceFiscale.setText(contoCorrenteAperto.getCodiceFiscale());
@@ -430,9 +492,7 @@ public class GUIMyBank extends javax.swing.JFrame {
txtSaldoIniziale.setEditable(false);
btnAprireContoCorrente.setEnabled(false);
btnDataDiNascita.setEnabled(false);
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
+ btnChiudereContoCorrente.setVisible(true);
}// GEN-LAST:event_btnAprireContoCorrenteActionPerformed
@@ -467,6 +527,7 @@ public class GUIMyBank extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAprireContoCorrente;
+ private javax.swing.JButton btnChiudereContoCorrente;
private javax.swing.JButton btnDataDiNascita;
private javax.swing.JButton btnListaMovimenti;
private javax.swing.JButton btnPrelievo;
diff --git a/src/logic/ContoCorrente.java b/src/logic/ContoCorrente.java
index 89bb01c..bd37bcd 100644
--- a/src/logic/ContoCorrente.java
+++ b/src/logic/ContoCorrente.java
@@ -4,9 +4,7 @@
*/
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;
@@ -30,15 +28,16 @@ public class ContoCorrente {
private static ArrayList numeriContiCorrenti = new ArrayList<>();
- @JsonFormat
- (shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private Date dataDiNascita;
+ StringBuilder sb = new StringBuilder();
+
public ContoCorrente() {
}
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldo,
- int numeroContoCorrente) throws IOException{
+ int numeroContoCorrente) {
this.nome = nome;
this.cognome = cognome;
this.codiceFiscale = codiceFiscale;
@@ -48,67 +47,67 @@ public class ContoCorrente {
numeriContiCorrenti.add(numeroContoCorrente);
log("Apertura del conto con saldo iniziale di " + this.saldo);
}
-
+
public static List getNumeriContiCorrenti() {
return numeriContiCorrenti;
}
public static void setNumeriContiCorrenti(List numeriContiCorrenti) {
- ContoCorrente.numeriContiCorrenti = (ArrayList)numeriContiCorrenti;
+ ContoCorrente.numeriContiCorrenti = (ArrayList) numeriContiCorrenti;
}
public int getNumeroContoCorrente() {
return numeroContoCorrente;
}
- public void versa(double quantita) throws IOException{
+ public void delNumeroContoCorrente() {
+ numeriContiCorrenti.removeLast();
+ }
+
+ public void versa(double quantita) {
this.saldo += quantita;
log("Versamento di " + quantita + " effettuato con successo.");
logSaldoCorrente();
}
-
- public void preleva(double quantita) throws IllegalArgumentException, IOException{
+
+ public void preleva(double quantita) throws IllegalArgumentException {
if (quantita > this.saldo) {
log("Tentato prelievo di " + quantita + " fallito per superamento saldo.");
logSaldoCorrente();
throw new IllegalArgumentException("La quantità desiderata eccede il saldo corrente.");
- }
- else {
+ } else {
this.saldo -= quantita;
log("Prelievo di " + quantita + " effettuato con successo.");
logSaldoCorrente();
}
}
- private void logSaldoCorrente() throws IOException{
+ private void logSaldoCorrente() {
log("Saldo corrente: " + this.saldo);
}
- private void log(String messaggio) throws IOException{
- StringBuilder sb = new StringBuilder();
+ private void log(String messaggio) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.sss dd/MM/yyyy");
- try (BufferedWriter bw = new BufferedWriter(
- new FileWriter(MyBank.PATH_CONTI + "movimenti_" + this.numeroContoCorrente + ".txt", true))) {
- sb.append("[");
- sb.append(sdf.format(new Date()));
- sb.append("] ");
- sb.append(messaggio);
- sb.append("\n");
+ sb.append("[");
+ sb.append(sdf.format(new Date()));
+ sb.append("] ");
+ sb.append(messaggio);
+ sb.append("\n");
+ }
- bw.write(sb.toString());
+ public void salvaLog() throws IOException {
+ try (BufferedWriter bw = new BufferedWriter(
+ new FileWriter(MyBank.PATH_CONTI + "movimenti_" + this.numeroContoCorrente + ".txt"))) {
+
+ bw.write(this.sb.toString());
} catch (IOException _) {
throw new IOException("Errore nella scrittura del movimento.");
}
}
@JsonIgnore
- 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.");
- }
+ public String getLogAsString() {
+ return this.sb.toString();
}
public String getNome() {
@@ -130,4 +129,8 @@ public class ContoCorrente {
public double getSaldo() {
return saldo;
}
+
+ public StringBuilder getSb() {
+ return this.sb;
+ }
}
\ No newline at end of file
diff --git a/src/logic/MyBank.java b/src/logic/MyBank.java
index 8a651a1..c3ae08a 100644
--- a/src/logic/MyBank.java
+++ b/src/logic/MyBank.java
@@ -14,7 +14,6 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
-import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;
@@ -36,53 +35,55 @@ public class MyBank {
static final String ERRORE_CONTI_VUOTO = "Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.";
public static final String PATH_CONTI = "./src/logic/conti/";
static final String FORMATO_DATA = "dd/MM/yyyy";
- private static ArrayList conti;
-
- public static void setConti(ArrayList conti) {
- MyBank.conti = conti;
- }
+ static final String ESTENSIONE_FILE = ".json";
+ private static ArrayList conti = new ArrayList<>();
public static ArrayList getConti() {
return conti;
}
- public static List importaConti() throws IOException{
- ArrayList conti = new ArrayList<>();
+ public static void importaConti() throws IOException {
File percorsoConti = new File(PATH_CONTI);
- ObjectMapper mapper = new ObjectMapper();
- mapper.setDateFormat(new SimpleDateFormat(FORMATO_DATA));
- StringBuilder sb;
- String riga;
if (percorsoConti.exists() && percorsoConti.listFiles().length != 0) {
for (File conto : percorsoConti.listFiles()) {
- if (conto.getName().substring(conto.getName().lastIndexOf(".")).equals(".json")) {
- try (BufferedReader bf = new BufferedReader(new FileReader(conto))) {
- sb = new StringBuilder();
- riga = bf.readLine();
-
- while (riga != null) {
- sb.append(riga);
- riga = bf.readLine();
- }
- conti.add(mapper.readerFor(ContoCorrente.class).readValue(sb.toString()));
-
- ArrayList numeriContiCorrenti = (ArrayList) ContoCorrente
- .getNumeriContiCorrenti();
- numeriContiCorrenti.add(conti.getLast().getNumeroContoCorrente());
- ContoCorrente.setNumeriContiCorrenti(numeriContiCorrenti);
-
- } catch (IOException e) {
- throw new IOException("Errore nella lettura del file di conto corrente:\n" + e.getMessage());
- }
+ if (conto.getName().substring(conto.getName().lastIndexOf(".")).equals(ESTENSIONE_FILE)) {
+ importaConto(conto);
}
}
}
- return conti;
}
- public static ContoCorrenteWrapper aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita,
- double saldoIniziale) throws IOException{
+ static ContoCorrente importaConto(File conto) throws IOException {
+ StringBuilder sb;
+ String riga;
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setDateFormat(new SimpleDateFormat(FORMATO_DATA));
+
+ try (BufferedReader bf = new BufferedReader(new FileReader(conto))) {
+ sb = new StringBuilder();
+ riga = bf.readLine();
+
+ while (riga != null) {
+ sb.append(riga);
+ riga = bf.readLine();
+ }
+ conti.add(mapper.readerFor(ContoCorrente.class).readValue(sb.toString()));
+
+ ArrayList numeriContiCorrenti = (ArrayList) ContoCorrente
+ .getNumeriContiCorrenti();
+ numeriContiCorrenti.add(conti.getLast().getNumeroContoCorrente());
+ ContoCorrente.setNumeriContiCorrenti(numeriContiCorrenti);
+
+ return conti.getLast();
+ } catch (IOException e) {
+ throw new IOException("Errore nella lettura del file di conto corrente:\n" + e.getMessage());
+ }
+ }
+
+ public static ContoCorrenteWrapper aggiungiConto(String nome, String cognome, String codiceFiscale,
+ Date dataDiNascita,
+ double saldoIniziale) {
int numeroContoCorrente;
ContoCorrente contoCorrente;
boolean exit = false;
@@ -92,10 +93,10 @@ public class MyBank {
numeroContoCorrente = Math.abs(codiceFiscale.hashCode());
if (ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
- for (; i < conti.size() && exit; i++) {
+ for (; i < conti.size() && !exit; i++) {
exit = conti.get(i).getNumeroContoCorrente() == numeroContoCorrente;
}
- contoCorrente = conti.get(i);
+ contoCorrente = conti.get(i - 1);
isImported = true;
} else {
File percorsoConti = new File(PATH_CONTI);
@@ -105,7 +106,6 @@ public class MyBank {
contoCorrente = new ContoCorrente(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale,
numeroContoCorrente);
conti.add(contoCorrente);
- salvaContoCorrente(contoCorrente);
isImported = false;
}
@@ -141,13 +141,32 @@ public class MyBank {
return valoreDouble;
}
- static void salvaContoCorrente(ContoCorrente conto) {
+ public static void salvaContoCorrente(ContoCorrente conto) throws IOException {
try (BufferedWriter bw = new BufferedWriter(
- new FileWriter(PATH_CONTI + "conto_" + conto.getNumeroContoCorrente() + ".json"))) {
+ new FileWriter(PATH_CONTI + "conto_" + conto.getNumeroContoCorrente() + ESTENSIONE_FILE))) {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
bw.write(ow.writeValueAsString(conto));
- } catch (IOException _) {
- System.out.println("Errore: impossibile salvare il conto corrente.");
+ conto.salvaLog();
+ } catch (IOException e) {
+ throw new IOException(
+ "Errore: impossibile salvare il conto corrente.\n" + e.getMessage() + "\n" + e.getStackTrace());
}
}
+
+ public static void salvaContiCorrenti() throws IOException {
+ for (ContoCorrente contoCorrente : conti) {
+ salvaContoCorrente(contoCorrente);
+ }
+ }
+
+ public static void annullaUltimoContoCorrente() throws IOException{
+ int numeroUltimoConto = conti.getLast().getNumeroContoCorrente();
+ conti.getLast().delNumeroContoCorrente();
+ conti.removeLast();
+ File percorsoUltimoConto = new File(PATH_CONTI + "conto_" + numeroUltimoConto + ESTENSIONE_FILE);
+ if (percorsoUltimoConto.exists()) {
+ importaConto(percorsoUltimoConto);
+ }
+ }
+
}
diff --git a/src/logic/conti/conto_692979128.json b/src/logic/conti/conto_692979128.json
deleted file mode 100644
index 75ff43f..0000000
--- a/src/logic/conti/conto_692979128.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "nome" : "Verde",
- "cognome" : "Bassanetti",
- "codiceFiscale" : "AAAAAA12A123Z",
- "saldo" : 200.0,
- "numeroContoCorrente" : 692979128,
- "dataDiNascita" : "04/07/2008"
-}
\ No newline at end of file
diff --git a/src/logic/conti/movimenti_692979128.txt b/src/logic/conti/movimenti_692979128.txt
deleted file mode 100644
index ceafdde..0000000
--- a/src/logic/conti/movimenti_692979128.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-[12:04:00.000 03/03/2026] Apertura del conto con saldo iniziale di 200.0
-[12:04:02.002 03/03/2026] Versamento di 5000.0 effettuato con successo.
-[12:04:02.002 03/03/2026] Saldo corrente: 5200.0
-[12:04:05.005 03/03/2026] Prelievo di 20.0 effettuato con successo.
-[12:04:05.005 03/03/2026] Saldo corrente: 5180.0
-[16:33:26.026 03/03/2026] Versamento di 2.0E11 effettuato con successo.
-[16:33:26.026 03/03/2026] Saldo corrente: 2.000000002E11
-[16:33:48.048 03/03/2026] Prelievo di 2.0E10 effettuato con successo.
-[16:33:48.048 03/03/2026] Saldo corrente: 1.800000002E11
-[16:33:57.057 03/03/2026] Tentato prelievo di 2.0E11 fallito per superamento saldo.
-[16:33:57.057 03/03/2026] Saldo corrente: 1.800000002E11
-[16:34:00.000 03/03/2026] Prelievo di 2000000.0 effettuato con successo.
-[16:34:00.000 03/03/2026] Saldo corrente: 1.799980002E11
-[16:34:05.005 03/03/2026] Tentato prelievo di 2.0E11 fallito per superamento saldo.
-[16:34:05.005 03/03/2026] Saldo corrente: 1.799980002E11
-[16:34:08.008 03/03/2026] Prelievo di 9.9999999E7 effettuato con successo.
-[16:34:08.008 03/03/2026] Saldo corrente: 1.79898000201E11
-[16:34:13.013 03/03/2026] Prelievo di 9.99999999E8 effettuato con successo.
-[16:34:13.013 03/03/2026] Saldo corrente: 1.78898000202E11
-[16:34:17.017 03/03/2026] Prelievo di 9.999999999E9 effettuato con successo.
-[16:34:17.017 03/03/2026] Saldo corrente: 1.68898000203E11
-[16:34:21.021 03/03/2026] Tentato prelievo di 1.0E17 fallito per superamento saldo.
-[16:34:21.021 03/03/2026] Saldo corrente: 1.68898000203E11
-[16:34:23.023 03/03/2026] Tentato prelievo di 9.999999999999E12 fallito per superamento saldo.
-[16:34:23.023 03/03/2026] Saldo corrente: 1.68898000203E11
-[16:34:25.025 03/03/2026] Prelievo di 9.99999999E8 effettuato con successo.
-[16:34:25.025 03/03/2026] Saldo corrente: 1.67898000204E11
-[16:34:29.029 03/03/2026] Prelievo di 9.999999999E9 effettuato con successo.
-[16:34:29.029 03/03/2026] Saldo corrente: 1.57898000205E11
-[16:34:37.037 03/03/2026] Prelievo di 1.0E11 effettuato con successo.
-[16:34:37.037 03/03/2026] Saldo corrente: 5.7898000205E10
-[16:34:43.043 03/03/2026] Prelievo di 5.0E10 effettuato con successo.
-[16:34:43.043 03/03/2026] Saldo corrente: 7.898000205E9
-[16:34:47.047 03/03/2026] Prelievo di 7.0E9 effettuato con successo.
-[16:34:47.047 03/03/2026] Saldo corrente: 8.98000205E8
-[16:34:50.050 03/03/2026] Prelievo di 8.0E8 effettuato con successo.
-[16:34:50.050 03/03/2026] Saldo corrente: 9.8000205E7
-[16:34:53.053 03/03/2026] Prelievo di 9.0E7 effettuato con successo.
-[16:34:53.053 03/03/2026] Saldo corrente: 8000205.0