diff --git a/build/classes/gui/GUIMyBank$1.class b/build/classes/gui/GUIMyBank$1.class index 78808c2..4765437 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 a399628..cd0505a 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 745d755..0e82a8c 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 46604c4..160d6b1 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 120dfd0..fa65b26 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 9d3b769..c116f6a 100644 Binary files a/build/classes/gui/GUIMyBank.class and b/build/classes/gui/GUIMyBank.class differ diff --git a/build/classes/logic/ContoCorrenteWrapper.class b/build/classes/logic/ContoCorrenteWrapper.class new file mode 100644 index 0000000..341a2d3 Binary files /dev/null and b/build/classes/logic/ContoCorrenteWrapper.class differ diff --git a/build/classes/logic/MyBank.class b/build/classes/logic/MyBank.class index b9400e3..eff9398 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 e4e008c..2c69ce1 100644 --- a/src/gui/GUIMyBank.java +++ b/src/gui/GUIMyBank.java @@ -11,6 +11,8 @@ import java.util.ArrayList; import java.util.Date; import logic.MyBank; import logic.ContoCorrente; +import logic.ContoCorrenteWrapper; + import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.border.Border; @@ -59,7 +61,8 @@ public class GUIMyBank extends javax.swing.JFrame { // //GEN-BEGIN:initComponents + // //GEN-BEGIN:initComponents private void initComponents() { lblNome = new javax.swing.JLabel(); @@ -147,88 +150,121 @@ public class GUIMyBank extends javax.swing.JFrame { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(99, 99, 99) - .addComponent(btnAprireContoCorrente) - .addContainerGap(187, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addGap(17, 17, 17) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblDataDiNascita) - .addComponent(lblSaldoIniziale)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(btnDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(txtSaldoIniziale))) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblNome) - .addComponent(lblCognome) - .addComponent(lblCodiceFiscale)) - .addGap(26, 26, 26) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, 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) - .addComponent(btnVersamento) - .addComponent(btnPrelievo) - .addComponent(btnListaMovimenti) - .addComponent(txtNumeroContoCorrente)) - .addGap(23, 23, 23)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1) - .addContainerGap()) - ); + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(99, 99, 99) + .addComponent(btnAprireContoCorrente) + .addContainerGap(187, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGap(17, 17, 17) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblDataDiNascita) + .addComponent(lblSaldoIniziale)) + .addGap(18, 18, 18) + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, + false) + .addGroup(layout.createSequentialGroup() + .addComponent(txtDataDiNascita, + javax.swing.GroupLayout.PREFERRED_SIZE, 64, + javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap( + javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(btnDataDiNascita, + javax.swing.GroupLayout.PREFERRED_SIZE, 39, + javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(txtSaldoIniziale))) + .addGroup(layout.createSequentialGroup() + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblNome) + .addComponent(lblCognome) + .addComponent(lblCodiceFiscale)) + .addGap(26, 26, 26) + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, + 113, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(txtCodiceFiscale, + javax.swing.GroupLayout.PREFERRED_SIZE, 115, + javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(txtCognome, + javax.swing.GroupLayout.PREFERRED_SIZE, 113, + javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, + 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) + .addComponent(btnVersamento) + .addComponent(btnPrelievo) + .addComponent(btnListaMovimenti) + .addComponent(txtNumeroContoCorrente)) + .addGap(23, 23, 23)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1) + .addContainerGap())); layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(14, 14, 14) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lblNome) - .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblNumeroContoCorrente)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lblCognome) - .addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(txtNumeroContoCorrente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lblCodiceFiscale) - .addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lblDataDiNascita) - .addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(btnDataDiNascita)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lblSaldoIniziale) - .addComponent(txtSaldoIniziale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(layout.createSequentialGroup() - .addComponent(btnVersamento) - .addGap(18, 18, 18) - .addComponent(btnPrelievo) - .addGap(18, 18, 18) - .addComponent(btnListaMovimenti))) - .addGap(18, 18, 18) - .addComponent(btnAprireContoCorrente) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane1) - .addGap(14, 14, 14)) - ); + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(14, 14, 14) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblNome) + .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, + javax.swing.GroupLayout.DEFAULT_SIZE, + javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblNumeroContoCorrente)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblCognome) + .addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, + javax.swing.GroupLayout.DEFAULT_SIZE, + javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(txtNumeroContoCorrente, javax.swing.GroupLayout.PREFERRED_SIZE, + javax.swing.GroupLayout.DEFAULT_SIZE, + javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblCodiceFiscale) + .addComponent(txtCodiceFiscale, + javax.swing.GroupLayout.PREFERRED_SIZE, + javax.swing.GroupLayout.DEFAULT_SIZE, + javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblDataDiNascita) + .addComponent(txtDataDiNascita, + javax.swing.GroupLayout.PREFERRED_SIZE, + javax.swing.GroupLayout.DEFAULT_SIZE, + javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(btnDataDiNascita)) + .addGap(18, 18, 18) + .addGroup(layout + .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblSaldoIniziale) + .addComponent(txtSaldoIniziale, + javax.swing.GroupLayout.PREFERRED_SIZE, + javax.swing.GroupLayout.DEFAULT_SIZE, + javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addComponent(btnVersamento) + .addGap(18, 18, 18) + .addComponent(btnPrelievo) + .addGap(18, 18, 18) + .addComponent(btnListaMovimenti))) + .addGap(18, 18, 18) + .addComponent(btnAprireContoCorrente) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1) + .addGap(14, 14, 14))); pack(); }// //GEN-END:initComponents @@ -364,8 +400,23 @@ public class GUIMyBank extends javax.swing.JFrame { } try { - contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale); - txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente())); + 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."); + txtNome.setText(contoCorrenteAperto.getNome()); + txtCognome.setText(contoCorrenteAperto.getCognome()); + txtCodiceFiscale.setText(contoCorrenteAperto.getCodiceFiscale()); + txtDataDiNascita.setText(MyBank.dataDiNascita(contoCorrenteAperto.getDataDiNascita())); + txtSaldoIniziale.setText(Double.toString(contoCorrenteAperto.getSaldo())); + txtNumeroContoCorrente.setText(Integer.toString(contoCorrenteAperto.getNumeroContoCorrente())); + lblSaldoIniziale.setText("Saldo"); + + } else { + txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente())); + } lblNumeroContoCorrente.setVisible(true); txtNumeroContoCorrente.setVisible(true); diff --git a/src/logic/ContoCorrenteWrapper.java b/src/logic/ContoCorrenteWrapper.java new file mode 100644 index 0000000..eafcdee --- /dev/null +++ b/src/logic/ContoCorrenteWrapper.java @@ -0,0 +1,19 @@ +package logic; + +public class ContoCorrenteWrapper { + ContoCorrente conto; + boolean isImported; + + public ContoCorrenteWrapper(ContoCorrente conto, boolean isImported) { + this.conto = conto; + this.isImported = isImported; + } + + public ContoCorrente getConto() { + return conto; + } + + public boolean isImported() { + return isImported; + } +} diff --git a/src/logic/MyBank.java b/src/logic/MyBank.java index 0af6a65..8a651a1 100644 --- a/src/logic/MyBank.java +++ b/src/logic/MyBank.java @@ -35,6 +35,7 @@ public class MyBank { static final String ERRORE_GENERICO = "Errore: opzione non valida."; 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) { @@ -49,7 +50,7 @@ public class MyBank { ArrayList conti = new ArrayList<>(); File percorsoConti = new File(PATH_CONTI); ObjectMapper mapper = new ObjectMapper(); - mapper.setDateFormat(new SimpleDateFormat("dd/MM/yyyy")); + mapper.setDateFormat(new SimpleDateFormat(FORMATO_DATA)); StringBuilder sb; String riga; @@ -80,11 +81,12 @@ public class MyBank { return conti; } - public static ContoCorrente aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita, + public static ContoCorrenteWrapper aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldoIniziale) throws IOException{ int numeroContoCorrente; ContoCorrente contoCorrente; boolean exit = false; + boolean isImported; int i = 0; numeroContoCorrente = Math.abs(codiceFiscale.hashCode()); @@ -94,6 +96,7 @@ public class MyBank { exit = conti.get(i).getNumeroContoCorrente() == numeroContoCorrente; } contoCorrente = conti.get(i); + isImported = true; } else { File percorsoConti = new File(PATH_CONTI); if (!percorsoConti.exists()) { @@ -103,9 +106,10 @@ public class MyBank { numeroContoCorrente); conti.add(contoCorrente); salvaContoCorrente(contoCorrente); + isImported = false; } - return contoCorrente; + return new ContoCorrenteWrapper(contoCorrente, isImported); } public static boolean isCodiceFiscaleValid(String codiceFiscale) { @@ -114,12 +118,17 @@ public class MyBank { } public static Date dataDiNascita(String dataDiNascita) throws ParseException { - final String FORMATO_DATA = "dd/MM/yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA); sdf.setLenient(false); return sdf.parse(dataDiNascita); } + public static String dataDiNascita(Date dataDiNascita) { + SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA); + sdf.setLenient(false); + return sdf.format(dataDiNascita); + } + public static double valoreDouble(String numeroDouble) throws NumberFormatException { double valoreDouble;