Appendix B Task 2: questionnaire and artefacts This section shows the questionnaire, the UML class and sequence diagrams, and the source code provided for the task 1 (T2) Buy a Ticket Unsuccessfully. It is worth noting that in case the subject has to perform the task using NO_DM we provided to him/her only the source code. On the other hand, we provided the UML class and sequence diagrams, and the source code, when the subject has to perform the task using DM. T2 - Questionnaire 1) To execute the application I have to execute: The method main() of the class Controllo The class Vista The class Modello 2) If the user select a ticket not available from the list, what happen?: The method actionperformed() of the class AzioneAcquistaBiglietto is executed An error is shown and the applicatin ends The class AzioneAcquistaBiglietto shows the message Ticket not available 3) What happen when the user select the action to buy a ticket without selecting a ticket before: The class AzioneIniziaAcquisto shows the message Nothing was selected The class AzioneAcquistaBiglietto shows the message Nothing was selected The class AzioneAcquistaBiglietto shows the message No ticket available 4) What is the class in charge of controlling the ticket: The class AzioneAcquistaBiglietto The class Controllo The class Modello 5) When an instance of the class Controllo (in the constructor) is created: An object of type Modello is created The method actionperformed() is executed No operation is exectuted 6) What is the class or method in charge of initializing graphical interfaces: The method inizializzaazioni() of the class Controllo The class Modello The method inizializzasottoviste() of the class Vista 7) What is the class or method in charge of loading the repository: The class Vista The method main() of the class Controllo The method caricaarchivio() of the class Controllo 8) What is class in charge of showing the tickets (available and not available): The class Vista The class PannelloPrincipale The class AzioneAcquistaBiglietto
9. What is the class that should be used to manage exceptional conditions: The class Modello The class Controllo The class Vista 10. A new graphical interface should be declared in: In the class Modello In the class Controllo In the method inizializzasottoviste() of the class Vista 11. To add the entry help to the Main (Initial) Menu, which of the following methods should be modified:: messaggi() inizializzaazioni() initcomponents() 12. If I want to manage the exceptional condition when a client is in the repository but he/she has not already bought a ticket I should modify the method actionperformed() of the class AzioneAcquistaBiglietto I should modify the class Controllo I should modify the method main() of the class Controllo 13. If I want to implement a new functionlity that allows to reserve a ticket before to buy it: I should add a method in the class Modello I should add a new control class I should modify the classe Modello 14. To add the possibility of cancelling the bought of a ticket, I should add: A control object and an entity object A boundary object and a control object A boundary object and an entity object 15. The exceptional conditions are: Managed by the field logger of the class Controllo Managed by the field logger of the class AzioneAcquistaBiglietto A suitable filed should be added in the class Vista
T2 Detailed UML class diagram
T2 Detailed UML sequence diagram
T2 JAVA source code See files: - AzioneAcquistaBiglietto.java - Controllo.java - Modello.java - PannelloPrincipale.java - Vista.java
AzioneAcquistaBiglietto.java Printed on 20/11/2008, 17.59.34 Page 1 1 package it.unibas.teatro.controllo; 2 3 import it.unibas.teatro.costanti; 4 import it.unibas.teatro.modello.posto; 5 import it.unibas.teatro.modello.teatro; 6 import it.unibas.teatro.vista.finestraspettatore; 7 import it.unibas.teatro.vista.pannelloprincipale; 8 import java.awt.event.actionevent; 9 import java.awt.event.keyevent; 10 import java.util.iterator; 11 import javax.swing.abstractaction; 12 import javax.swing.action; 13 import javax.swing.keystroke; 14 15 public class AzioneAcquistaBiglietto extends AbstractAction{ 16 17 private Controllo controllo; 18 19 public AzioneAcquistaBiglietto(Controllo controllo){ 20 this.controllo = controllo; 21 this.putvalue(action.name, "InserisciSpettatore"); 22 this.putvalue(action.short_description,"inserisce i dati dello spettatore"); 23 this.putvalue(action.mnemonic_key, new Integer(KeyEvent.VK_I)); 24 this.putvalue(action.accelerator_key, KeyStroke.getKeyStroke("ctrl I")); 25 } 26 27 public void actionperformed(actionevent e){ 28 String messaggio = ""; 29 PannelloPrincipale p =(PannelloPrincipale) this.controllo.getvista().getsottovista(costanti. VISTA_PANNELLO_PRINCIPALE); 30 Teatro t=(teatro)this.controllo.getmodello().getbean(costanti.teatro); 31 Iterator i=t.getlistaposti().iterator(); 32 while(i.hasnext()){ 33 Posto posto =(Posto) i.next(); 34 if(posto.isstato() == true){ 35 int selezione = p.getselectedindex(); 36 if(selezione!=-1){ 37 posto = t.getposto(selezione); 38 if(posto.isstato() == false){ 39 messaggio+= "Posto gia' occupato\n"; 40 this.controllo.getvista().finestramessaggi(messaggio); 41 return; 42 } 43 this.controllo.getmodello().putbean(costanti.posto, posto); 44 FinestraSpettatore fs =(FinestraSpettatore) this.controllo.getvista(). getsottovista(costanti.vista_finestra_spettatore); 45 fs.setvisible(true); 46 return; 47 } 48 else{ 49 messaggio+= "Non hai selezionato nulla\n"; 50 this.controllo.getvista().finestramessaggi(messaggio); 51 } 52 } 53 } 54 messaggio+= "Non ci sono posti disponibili\n"; 55 this.controllo.getvista().finestramessaggi(messaggio); 56 System.exit(0); 57 } 58 } C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\azioneacquist
Controllo.java Printed on 20/11/2008, 17.53.36 Page 1 1 package it.unibas.teatro.controllo; 2 3 import it.unibas.teatro.costanti; 4 import it.unibas.teatro.modello.modello; 5 import it.unibas.teatro.modello.teatro; 6 import it.unibas.teatro.persistenza.daoteatro; 7 import it.unibas.teatro.persistenza.idaoteatro; 8 import it.unibas.teatro.vista.vista; 9 import java.util.hashmap; 10 import java.util.map; 11 import javax.swing.action; 12 import org.apache.commons.logging.log; 13 import org.apache.commons.logging.logfactory; 14 15 public class Controllo{ 16 17 private Vista vista; 18 private Modello modello; 19 private Map mappaazioni = new HashMap(); 20 private Log logger = LogFactory.getLog(Controllo.class); 21 public Controllo(){ 22 this.inizializzaazioni(); 23 this.modello = new Modello(); 24 this.caricaarchivio(); 25 this.vista = new Vista(this, modello); 26 } 27 28 public void inizializzaazioni(){ 29 this.mappaazioni.put(costanti.azione_esci, new AzioneEsci(this)); 30 this.mappaazioni.put(costanti.azione_acquista_biglietto, new AzioneAcquistaBiglietto( this)); 31 this.mappaazioni.put(costanti.azione_invia, new AzioneInvia(this)); 32 this.mappaazioni.put(costanti.azione_inizia_acquisto, new AzioneIniziaAcquisto(this)); 33 this.mappaazioni.put(costanti.azione_ricerca, new AzioneRicercaPostoSpettatore(this)); 34 this.mappaazioni.put(costanti.azione_visualizza_tabella_biglietti, new AzioneVisualizzaTabellaBiglietti(this)); 35 } 36 37 public Action getazione(string nome){ 38 return(action) this.mappaazioni.get(nome); 39 } 40 41 public void caricaarchivio(){ 42 IDAOTeatro daoteatro=new DAOTeatro(); 43 try{ 44 Teatro teatro=(teatro) daoteatro.carica(""); 45 this.getmodello().putbean(costanti.teatro,teatro); 46 }catch(exception e){ 47 logger.error("errore nel caricamento!!"+e); 48 } 49 } 50 51 public Vista getvista(){ 52 return vista; 53 } 54 55 public void setvista(vista vista){ 56 this.vista=vista; 57 } 58 59 public Modello getmodello(){ 60 return modello; 61 } C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\controllo.java
Controllo.java Printed on 20/11/2008, 17.53.36 Page 2 62 63 public void setmodello(modello modello){ 64 this.modello = modello; 65 } 66 67 public Map getmappaazioni(){ 68 return mappaazioni; 69 } 70 71 public void setmappaazioni(map mappaazioni){ 72 this.mappaazioni=mappaazioni; 73 } 74 75 public static void main(string args[]){ 76 java.awt.eventqueue.invokelater(new Runnable(){ 77 public void run(){ 78 Controllo controllo = new Controllo(); 79 } 80 }); 81 } 82 } C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\controllo.java
Modello.java Printed on 20/11/2008, 17.57.29 Page 1 1 package it.unibas.teatro.modello; 2 3 import java.util.hashmap; 4 import java.util.map; 5 6 public class Modello{ 7 8 private Map mappabean = new HashMap(); 9 10 public Modello(){ 11 } 12 13 public Object getbean(string nome){ 14 return this.mappabean.get(nome); 15 } 16 17 publicvoid putbean(string nome,object bean){ 18 this.mappabean.put(nome,bean); 19 } 20 } C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\modello.java
PannelloPrincipale.java Printed on 20/11/2008, 17.51.02 Page 1 1 package it.unibas.teatro.vista; 2 3 import it.unibas.teatro.costanti; 4 import it.unibas.teatro.controllo.controllo; 5 import it.unibas.teatro.modello.modello; 6 import it.unibas.teatro.modello.teatro; 7 8 public class PannelloPrincipale extends javax.swing.jpanel{ 9 10 private Vista vista; 11 private Controllo controllo; 12 private Modello modello; 13 14 public PannelloPrincipale(Vista vista){ 15 this.vista=vista; 16 this.modello = vista.getmodello(); 17 this.controllo = vista.getcontrollo(); 18 initcomponents(); 19 this.visualizzatabella(); 20 this.inizializzabottoni(); 21 } 22 23 public Controllo getcontrollo(){ 24 return controllo; 25 } 26 27 public void setcontrollo(controllo controllo){ 28 this.controllo = controllo; 29 } 30 31 public Modello getmodello(){ 32 return modello; 33 } 34 35 public void setmodello(modello modello){ 36 this.modello = modello; 37 } 38 39 public void visualizzatabella(){ 40 Teatro teatro=(teatro)this.controllo.getmodello().getbean(costanti.teatro); 41 ModelloTabella mt = new ModelloTabella(teatro); 42 this.tabellaposti.setmodel(mt); 43 } 44 45 public int getselectedindex(){ 46 return this.tabellaposti.getselectedrow(); 47 } 48 49 public void inizializzabottoni(){ 50 this.bottonevisualizza.setaction(this.controllo.getazione(costanti. AZIONE_ACQUISTA_BIGLIETTO)); 51 } 52 53 private void initcomponents(){ 54 labelregistra = new javax.swing.jlabel(); 55 jscrollpane1 = new javax.swing.jscrollpane(); 56 tabellaposti = new javax.swing.jtable(); 57 labelteatro = new javax.swing.jlabel(); 58 bottonevisualizza = new javax.swing.jbutton(); 59 labelregistra.settext("registra ACQUISTO BIGLIETTO"); 60 tabellaposti.setmodel(new javax.swing.table.defaulttablemodel( 61 new Object[][]{ 62 {null, null, null, null}, C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\pannelloprinci
PannelloPrincipale.java Printed on 20/11/2008, 17.51.02 Page 2 63 {null, null, null, null}, 64 {null, null, null, null}, 65 {null, null, null, null} 66 }, 67 new String[]{ 68 "Title 1", "Title 2", "Title 3", "Title 4" 69 } 70 )); 71 jscrollpane1.setviewportview(tabellaposti); 72 labelteatro.settext("teatro DON BOSCO"); 73 bottonevisualizza.settext("visualizza"); 74 org.jdesktop.layout.grouplayout layout=new org.jdesktop.layout.grouplayout(this); 75 this.setlayout(layout); 76 layout.sethorizontalgroup( 77 layout.createparallelgroup(org.jdesktop.layout.grouplayout.leading) 78.add(layout.createSequentialGroup() 79.addContainerGap() 80.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 81.add(jScrollPane1, org.jdesktop.layout.grouplayout.preferred_size, 375, org.jdesktop. layout.grouplayout.preferred_size) 82.add(labelRegistra) 83.add(labelTeatro) 84.add(bottoneVisualizza)) 85.addContainerGap(15, Short.MAX_VALUE)) 86 ); 87 layout.setverticalgroup( 88 layout.createparallelgroup(org.jdesktop.layout.grouplayout.leading) 89.add(layout.createSequentialGroup() 90.addContainerGap() 91.add(labelTeatro) 92.add(20, 20, 20) 93.add(labelRegistra) 94.add(30, 30, 30) 95.add(jScrollPane1, org.jdesktop.layout.grouplayout.preferred_size, 83, org.jdesktop. layout.grouplayout.preferred_size) 96.add(32, 32, 32) 97.add(bottoneVisualizza) 98.addContainerGap(90, Short.MAX_VALUE)) 99 ); 100 } 101 private javax.swing.jbutton bottonevisualizza; 102 private javax.swing.jscrollpane jscrollpane1; 103 private javax.swing.jlabel labelregistra; 104 private javax.swing.jlabel labelteatro; 105 private javax.swing.jtable tabellaposti; 106 } C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\pannelloprinci
Vista.java Printed on 20/11/2008, 17.55.33 Page 1 1 package it.unibas.teatro.vista; 2 3 import it.unibas.teatro.costanti; 4 import it.unibas.teatro.controllo.controllo; 5 import it.unibas.teatro.modello.modello; 6 import java.util.hashmap; 7 import java.util.map; 8 import javax.swing.joptionpane; 9 10 public class Vista extends javax.swing.jframe{ 11 12 private Controllo controllo; 13 private Modello modello; 14 private Map mappasottoviste = new HashMap(); 15 16 public Vista(Controllo controllo,modello modello){ 17 this.modello = modello; 18 this.controllo = controllo; 19 initcomponents(); 20 this.inizializzamenu(); 21 this.inizializzasottoviste(); 22 this.postcomponent(); 23 } 24 25 public void postcomponent(){ 26 this.pack(); 27 this.setvisible(true); 28 } 29 30 public void inizializzamenu(){ 31 this.esci.setaction(this.getcontrollo().getazione(costanti.azione_esci)); 32 this.acquistabiglietto.setaction(this.controllo.getazione(costanti.azione_inizia_acquisto )); 33 this.ricercapostocliente.setaction(this.controllo.getazione(costanti.azione_ricerca)); 34 } 35 36 public Object getsottovista(string nome){ 37 return this.mappasottoviste.get(nome); 38 } 39 40 public void inizializzasottoviste(){ 41 PannelloPrincipale pp = new PannelloPrincipale(this); 42 this.mappasottoviste.put(costanti.vista_pannello_principale,pp); 43 FinestraSpettatore fs = new FinestraSpettatore(this); 44 this.mappasottoviste.put(costanti.vista_finestra_spettatore,fs); 45 RicercaPosto rp = new RicercaPosto(this); 46 this.mappasottoviste.put(costanti.vista_ricerca_posto,rp); 47 Biglietti b = new Biglietti(this); 48 this.mappasottoviste.put(costanti.vista_biglietti,b); 49 } 50 51 public Controllo getcontrollo(){ 52 return controllo; 53 } 54 55 public void setcontrollo(controllo controllo){ 56 this.controllo = controllo; 57 } 58 59 public Modello getmodello(){ 60 return modello; 61 } 62 C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\vista.java F
Vista.java Printed on 20/11/2008, 17.55.33 Page 2 63 public void setmodello(modello modello){ 64 this.modello = modello; 65 } 66 67 public void finestramessaggi(string messaggio){ 68 JOptionPane op=new JOptionPane(); 69 op.showmessagedialog(this,messaggio); 70 } 71 72 73 74 75 76 77 private void initcomponents(){ 78 jmenubar1 = new javax.swing.jmenubar(); 79 jmenu1 = new javax.swing.jmenu(); 80 esci = new javax.swing.jmenuitem(); 81 acquistabiglietto = new javax.swing.jmenuitem(); 82 ricercapostocliente = new javax.swing.jmenuitem(); 83 setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); 84 settitle("teatro"); 85 jmenu1.settext("file"); 86 esci.settext("item"); 87 jmenu1.add(esci); 88 acquistabiglietto.settext("item"); 89 jmenu1.add(acquistabiglietto); 90 ricercapostocliente.settext("item"); 91 jmenu1.add(ricercapostocliente); 92 jmenubar1.add(jmenu1); 93 setjmenubar(jmenubar1); 94 pack(); 95 } 96 97 private javax.swing.jmenuitem acquistabiglietto; 98 private javax.swing.jmenuitem esci; 99 private javax.swing.jmenu jmenu1; 100 private javax.swing.jmenubar jmenubar1; 101 private javax.swing.jmenuitem ricercapostocliente; 102 } C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoconinsuccesso\vista.java F