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 packageit.unibas.teatro.controllo;
2
3 importit.unibas.teatro.Costanti;
4 importit.unibas.teatro.modello.Posto;
5 importit.unibas.teatro.modello.Teatro;
6 importit.unibas.teatro.vista.FinestraSpettatore;
7 importit.unibas.teatro.vista.PannelloPrincipale;
8 importjava.awt.event.ActionEvent;
9 importjava.awt.event.KeyEvent;
10 importjava.util.Iterator;
11 importjavax.swing.AbstractAction;
12 importjavax.swing.Action;
13 importjavax.swing.KeyStroke;
14
15 public classAzioneAcquistaBiglietto extendsAbstractAction { 16
17 privateControllo controllo;
18
19 publicAzioneAcquistaBiglietto(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,newInteger(KeyEvent.VK_I));
24 this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl I"));
25 }
26
27 public voidactionPerformed(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 intselezione = 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\AzioneAcquistaBiglietto.java — File date: 20/11/2008 — File time: 17.59.30
Controllo.java — Printed on 20/11/2008, 17.53.36 — Page 1
1 packageit.unibas.teatro.controllo;
2
3 importit.unibas.teatro.Costanti;
4 importit.unibas.teatro.modello.Modello;
5 importit.unibas.teatro.modello.Teatro;
6 importit.unibas.teatro.persistenza.DAOTeatro;
7 importit.unibas.teatro.persistenza.IDAOTeatro;
8 importit.unibas.teatro.vista.Vista;
9 importjava.util.HashMap;
10 importjava.util.Map;
11 importjavax.swing.Action;
12 importorg.apache.commons.logging.Log;
13 importorg.apache.commons.logging.LogFactory;
14
15 public classControllo { 16
17 privateVista vista;
18 privateModello modello;
19 privateMap mappaAzioni =newHashMap();
20 privateLog logger = LogFactory.getLog(Controllo.class);
21 publicControllo() {
22 this.inizializzaAzioni();
23 this.modello =newModello();
24 this.caricaArchivio();
25 this.vista =newVista(this, modello);
26 }
27
28 public voidinizializzaAzioni(){
29 this.mappaAzioni.put(Costanti.AZIONE_ESCI,newAzioneEsci(this));
30 this.mappaAzioni.put(Costanti.AZIONE_ACQUISTA_BIGLIETTO,newAzioneAcquistaBiglietto(
this));
31 this.mappaAzioni.put(Costanti.AZIONE_INVIA,newAzioneInvia(this));
32 this.mappaAzioni.put(Costanti.AZIONE_INIZIA_ACQUISTO,newAzioneIniziaAcquisto(this));
33 this.mappaAzioni.put(Costanti.AZIONE_RICERCA,newAzioneRicercaPostoSpettatore(this));
34 this.mappaAzioni.put(Costanti.AZIONE_VISUALIZZA_TABELLA_BIGLIETTI,new AzioneVisualizzaTabellaBiglietti(this));
35 }
36
37 publicAction getAzione(String nome){
38 return(Action)this.mappaAzioni.get(nome);
39 }
40
41 public voidcaricaArchivio(){
42 IDAOTeatro daoTeatro =newDAOTeatro();
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 publicVista getVista() { 52 returnvista;
53 }
54
55 public voidsetVista(Vista vista) { 56 this.vista = vista;
57 }
58
59 publicModello getModello() { 60 returnmodello;
61 }
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\Controllo.java — File date: 20/11/2008 — File time: 17.53.32
Controllo.java — Printed on 20/11/2008, 17.53.36 — Page 2
62
63 public voidsetModello(Modello modello) { 64 this.modello = modello;
65 }
66
67 publicMap getMappaAzioni() { 68 returnmappaAzioni;
69 }
70
71 public voidsetMappaAzioni(Map mappaAzioni) { 72 this.mappaAzioni = mappaAzioni;
73 }
74
75 public static voidmain(String args[]) {
76 java.awt.EventQueue.invokeLater(newRunnable() {
77 public voidrun() {
78 Controllo controllo =newControllo();
79 }
80 });
81 }
82 }
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\Controllo.java — File date: 20/11/2008 — File time: 17.53.32
Modello.java — Printed on 20/11/2008, 17.57.29 — Page 1
1 packageit.unibas.teatro.modello;
2
3 importjava.util.HashMap;
4 importjava.util.Map;
5
6 public classModello { 7
8 privateMap mappaBean =newHashMap();
9
10 publicModello() {
11 }
12
13 publicObject getBean(String nome){
14 return this.mappaBean.get(nome);
15 }
16
17 public voidputBean(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 — File date: 20/11/2008 — File time: 17.56.50
PannelloPrincipale.java — Printed on 20/11/2008, 17.51.02 — Page 1
1 packageit.unibas.teatro.vista;
2
3 importit.unibas.teatro.Costanti;
4 importit.unibas.teatro.controllo.Controllo;
5 importit.unibas.teatro.modello.Modello;
6 importit.unibas.teatro.modello.Teatro;
7
8 public classPannelloPrincipale extendsjavax.swing.JPanel { 9
10 privateVista vista;
11 privateControllo controllo;
12 privateModello modello;
13
14 publicPannelloPrincipale(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 publicControllo getControllo() { 24 returncontrollo;
25 }
26
27 public voidsetControllo(Controllo controllo) { 28 this.controllo = controllo;
29 }
30
31 publicModello getModello() { 32 returnmodello;
33 }
34
35 public voidsetModello(Modello modello) { 36 this.modello = modello;
37 }
38
39 public voidvisualizzaTabella(){
40 Teatro teatro = (Teatro)this.controllo.getModello().getBean(Costanti.TEATRO);
41 ModelloTabella mt =newModelloTabella(teatro);
42 this.tabellaPosti.setModel(mt);
43 }
44
45 public intgetSelectedIndex(){
46 return this.tabellaPosti.getSelectedRow();
47 }
48
49 public voidinizializzaBottoni(){
50 this.bottoneVisualizza.setAction(this.controllo.getAzione(Costanti.
AZIONE_ACQUISTA_BIGLIETTO));
51 }
52
53 private voidinitComponents() {
54 labelRegistra =newjavax.swing.JLabel();
55 jScrollPane1 =newjavax.swing.JScrollPane();
56 tabellaPosti =newjavax.swing.JTable();
57 labelTeatro =newjavax.swing.JLabel();
58 bottoneVisualizza =newjavax.swing.JButton();
59 labelRegistra.setText("REGISTRA ACQUISTO BIGLIETTO");
60 tabellaPosti.setModel(newjavax.swing.table.DefaultTableModel(
61 newObject [][] {
62 {null,null,null,null},
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\PannelloPrincipale.java — File date: 20/11/2008 — File time: 17.50.55
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 newString [] {
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 =neworg.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 privatejavax.swing.JButton bottoneVisualizza;
102 privatejavax.swing.JScrollPane jScrollPane1;
103 privatejavax.swing.JLabel labelRegistra;
104 privatejavax.swing.JLabel labelTeatro;
105 privatejavax.swing.JTable tabellaPosti;
106 }
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\PannelloPrincipale.java — File date: 20/11/2008 — File time: 17.50.55
Vista.java — Printed on 20/11/2008, 17.55.33 — Page 1
1 packageit.unibas.teatro.vista;
2
3 importit.unibas.teatro.Costanti;
4 importit.unibas.teatro.controllo.Controllo;
5 importit.unibas.teatro.modello.Modello;
6 importjava.util.HashMap;
7 importjava.util.Map;
8 importjavax.swing.JOptionPane;
9
10 public classVista extendsjavax.swing.JFrame { 11
12 privateControllo controllo ; 13 privateModello modello;
14 privateMap mappaSottoviste =newHashMap();
15
16 publicVista(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 voidpostComponent(){
26 this.pack();
27 this.setVisible(true);
28 }
29
30 public voidinizializzaMenu(){
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 publicObject getSottovista(String nome){
37 return this.mappaSottoviste.get(nome);
38 }
39
40 public voidinizializzaSottoviste(){
41 PannelloPrincipale pp =newPannelloPrincipale(this);
42 this.mappaSottoviste.put(Costanti.VISTA_PANNELLO_PRINCIPALE,pp);
43 FinestraSpettatore fs =newFinestraSpettatore(this);
44 this.mappaSottoviste.put(Costanti.VISTA_FINESTRA_SPETTATORE,fs);
45 RicercaPosto rp =newRicercaPosto(this);
46 this.mappaSottoviste.put(Costanti.VISTA_RICERCA_POSTO,rp);
47 Biglietti b =newBiglietti(this);
48 this.mappaSottoviste.put(Costanti.VISTA_BIGLIETTI,b);
49 }
50
51 publicControllo getControllo() { 52 returncontrollo;
53 }
54
55 public voidsetControllo(Controllo controllo) { 56 this.controllo = controllo;
57 }
58
59 publicModello getModello() { 60 returnmodello;
61 }
62
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\Vista.java — File date: 20/11/2008 — File time: 17.55.04
Vista.java — Printed on 20/11/2008, 17.55.33 — Page 2
63 public voidsetModello(Modello modello) { 64 this.modello = modello;
65 }
66
67 public voidfinestraMessaggi(String messaggio){
68 JOptionPane op =newJOptionPane();
69 op.showMessageDialog(this,messaggio);
70 }
71 72 73 74 75 76
77 private voidinitComponents() {
78 jMenuBar1 =newjavax.swing.JMenuBar();
79 jMenu1 =newjavax.swing.JMenu();
80 esci =newjavax.swing.JMenuItem();
81 acquistaBiglietto =newjavax.swing.JMenuItem();
82 ricercaPostoCliente =newjavax.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 privatejavax.swing.JMenuItem acquistaBiglietto;
98 privatejavax.swing.JMenuItem esci;
99 privatejavax.swing.JMenu jMenu1;
100 privatejavax.swing.JMenuBar jMenuBar1;
101 privatejavax.swing.JMenuItem ricercaPostoCliente;
102 }
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\Vista.java — File date: 20/11/2008 — File time: 17.55.04