Esportazione ed importazione conti correnti corretta

This commit is contained in:
La Programmatrice Verde
2026-03-03 23:00:00 +01:00
parent 8dca146c03
commit de989d43f5
18 changed files with 209 additions and 194 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -26,7 +26,9 @@
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="99" max="-2" attributes="0"/>
<Component id="btnAprireContoCorrente" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="187" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnChiudereContoCorrente" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
@@ -60,7 +62,7 @@
</Group>
</Group>
</Group>
<EmptySpace pref="39" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="lblNumeroContoCorrente" max="32767" attributes="0"/>
<Component id="btnVersamento" min="-2" max="-2" attributes="0"/>
@@ -120,7 +122,10 @@
</Group>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnAprireContoCorrente" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnAprireContoCorrente" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnChiudereContoCorrente" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
@@ -238,5 +243,13 @@
</Component>
<Component class="javax.swing.JTextField" name="txtNumeroContoCorrente">
</Component>
<Component class="javax.swing.JButton" name="btnChiudereContoCorrente">
<Properties>
<Property name="text" type="java.lang.String" value="Chiudere conto corrente"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnChiudereContoCorrenteActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

Binary file not shown.

View File

@@ -1,8 +0,0 @@
{
"nome" : "Verde",
"cognome" : "Bassanetti",
"codiceFiscale" : "AAAAAA12A123Z",
"saldo" : 200.0,
"numeroContoCorrente" : 692979128,
"dataDiNascita" : "04/07/2008"
}

View File

@@ -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

View File

@@ -26,7 +26,9 @@
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="99" max="-2" attributes="0"/>
<Component id="btnAprireContoCorrente" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="187" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnChiudereContoCorrente" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
@@ -60,7 +62,7 @@
</Group>
</Group>
</Group>
<EmptySpace pref="39" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="lblNumeroContoCorrente" max="32767" attributes="0"/>
<Component id="btnVersamento" min="-2" max="-2" attributes="0"/>
@@ -120,7 +122,10 @@
</Group>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnAprireContoCorrente" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnAprireContoCorrente" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnChiudereContoCorrente" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
@@ -238,5 +243,13 @@
</Component>
<Component class="javax.swing.JTextField" name="txtNumeroContoCorrente">
</Component>
<Component class="javax.swing.JButton" name="btnChiudereContoCorrente">
<Properties>
<Property name="text" type="java.lang.String" value="Chiudere conto corrente"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnChiudereContoCorrenteActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -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<ContoCorrente> conti = (ArrayList<ContoCorrente>) 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 {
// <editor-fold defaultstate="collapsed" desc="Generated
// <editor-fold defaultstate="collapsed" desc="Generated
// <editor-fold defaultstate="collapsed" desc="Generated
// <editor-fold defaultstate="collapsed" desc="Generated
// Code">//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();
}// </editor-fold>//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;

View File

@@ -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<Integer> 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;
@@ -54,61 +53,61 @@ public class ContoCorrente {
}
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) 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;
}
}

View File

@@ -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<ContoCorrente> conti;
public static void setConti(ArrayList<ContoCorrente> conti) {
MyBank.conti = conti;
}
static final String ESTENSIONE_FILE = ".json";
private static ArrayList<ContoCorrente> conti = new ArrayList<>();
public static ArrayList<ContoCorrente> getConti() {
return conti;
}
public static List<ContoCorrente> importaConti() throws IOException{
ArrayList<ContoCorrente> 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<Integer> numeriContiCorrenti = (ArrayList<Integer>) 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<Integer> numeriContiCorrenti = (ArrayList<Integer>) 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);
}
}
}

View File

@@ -1,8 +0,0 @@
{
"nome" : "Verde",
"cognome" : "Bassanetti",
"codiceFiscale" : "AAAAAA12A123Z",
"saldo" : 200.0,
"numeroContoCorrente" : 692979128,
"dataDiNascita" : "04/07/2008"
}

View File

@@ -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