diff --git a/build/classes/gui/GUIMyBank$1.class b/build/classes/gui/GUIMyBank$1.class index fe30ed2..041d0fb 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 dc5357b..43255d9 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 a119ad2..7b7ff72 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 832852b..dd87cbc 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 1427092..2181969 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.class b/build/classes/gui/GUIMyBank.class index 9c1572a..bbee831 100644 Binary files a/build/classes/gui/GUIMyBank.class and b/build/classes/gui/GUIMyBank.class differ diff --git a/build/classes/logic/ContoCorrente.class b/build/classes/logic/ContoCorrente.class index 9508b29..e997d5a 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 def2def..ad5a391 100644 Binary files a/build/classes/logic/MyBank.class and b/build/classes/logic/MyBank.class differ diff --git a/src/gui/GUIMyBank.java b/src/gui/GUIMyBank.java index 5f4b411..f5bf08b 100644 --- a/src/gui/GUIMyBank.java +++ b/src/gui/GUIMyBank.java @@ -5,6 +5,7 @@ package gui; import java.awt.Color; +import java.io.IOException; import java.text.ParseException; import java.util.Date; import java.util.regex.Pattern; @@ -264,8 +265,12 @@ public class GUIMyBank extends javax.swing.JFrame { }// //GEN-END:initComponents private void btnListaMovimentiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnListaMovimentiActionPerformed - txtaListaMovimenti.setText(contoCorrente.getLogOperazioni()); - txtaListaMovimenti.setVisible(true); + try { + txtaListaMovimenti.setText(contoCorrenteAperto.getLog()); + txtaListaMovimenti.setVisible(true); + } catch (IOException e) { + JOptionPane.showMessageDialog(null, e.getMessage()); + } }// GEN-LAST:event_btnListaMovimentiActionPerformed private void txtNomeFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_txtNomeFocusGained @@ -303,6 +308,8 @@ 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 @@ -325,6 +332,8 @@ 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 @@ -385,21 +394,25 @@ public class GUIMyBank extends javax.swing.JFrame { return; } - this.contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale); - txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente())); + try { + this.contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale); + txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente())); - lblNumeroContoCorrente.setVisible(true); - txtNumeroContoCorrente.setVisible(true); - btnVersamento.setVisible(true); - btnPrelievo.setVisible(true); - btnListaMovimenti.setVisible(true); - txtNome.setEditable(false); - txtCognome.setEditable(false); - txtCodiceFiscale.setEditable(false); - txtDataDiNascita.setEditable(false); - txtSaldoIniziale.setEditable(false); - btnAprireContoCorrente.setEnabled(false); - btnDataDiNascita.setEnabled(false); + lblNumeroContoCorrente.setVisible(true); + txtNumeroContoCorrente.setVisible(true); + btnVersamento.setVisible(true); + btnPrelievo.setVisible(true); + btnListaMovimenti.setVisible(true); + txtNome.setEditable(false); + txtCognome.setEditable(false); + txtCodiceFiscale.setEditable(false); + txtDataDiNascita.setEditable(false); + txtSaldoIniziale.setEditable(false); + btnAprireContoCorrente.setEnabled(false); + btnDataDiNascita.setEnabled(false); + } catch (IOException e) { + JOptionPane.showMessageDialog(null, e.getMessage()); + } }// GEN-LAST:event_btnAprireContoCorrenteActionPerformed diff --git a/src/logic/ContoCorrente.java b/src/logic/ContoCorrente.java index 0c702ab..822cdb5 100644 --- a/src/logic/ContoCorrente.java +++ b/src/logic/ContoCorrente.java @@ -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."); } } diff --git a/src/logic/MyBank.java b/src/logic/MyBank.java index 084bc91..7943623 100644 --- a/src/logic/MyBank.java +++ b/src/logic/MyBank.java @@ -61,23 +61,6 @@ public class MyBank { switch (scelta) { case 0: break; - case 3: - if (conti.isEmpty()) { - System.out.println(ERRORE_CONTI_VUOTO); - } else { - preleva(conti); - System.out.println("Prelievo effettuato con successo."); - } - pausa(); - break; - case 4: - if (conti.isEmpty()) { - System.out.println(ERRORE_CONTI_VUOTO); - } else { - stampaLog(conti); - } - pausa(); - break; default: System.out.println(ERRORE_GENERICO); pausa(); @@ -133,7 +116,7 @@ public class MyBank { } public static ContoCorrente aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita, - double saldoIniziale) { + double saldoIniziale) throws IOException{ int numeroContoCorrente; ContoCorrente contoCorrente; boolean exit = false; @@ -193,13 +176,4 @@ public class MyBank { System.out.println("Errore: impossibile salvare il conto corrente."); } } - - static void stampaLog(ArrayList conti) { - try (BufferedReader br = new BufferedReader( - new FileReader(PATH_CONTI + "movimenti_" + selezionaConto(conti).getNumeroContoCorrente() + ".txt"))) { - System.out.println(br.readAllAsString()); - } catch (IOException _) { - System.out.println("Errore nella lettura dei movimenti."); - } - } }