Appendix B – Task 2: questionnaire and artefacts This section

annuncio pubblicitario
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package it.unibas.teatro.controllo;
import
import
import
import
import
import
import
import
import
import
import
it.unibas.teatro.Costanti;
it.unibas.teatro.modello.Posto;
it.unibas.teatro.modello.Teatro;
it.unibas.teatro.vista.FinestraSpettatore;
it.unibas.teatro.vista.PannelloPrincipale;
java.awt.event.ActionEvent;
java.awt.event.KeyEvent;
java.util.Iterator;
javax.swing.AbstractAction;
javax.swing.Action;
javax.swing.KeyStroke;
public class AzioneAcquistaBiglietto extends AbstractAction {
private Controllo controllo;
public AzioneAcquistaBiglietto(Controllo controllo) {
this.controllo = controllo;
this.putValue(Action.NAME, "InserisciSpettatore");
this.putValue(Action.SHORT_DESCRIPTION,"Inserisce i dati dello spettatore");
this.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_I));
this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl I"));
}
public void actionPerformed(ActionEvent e) {
String messaggio = "";
PannelloPrincipale p = (PannelloPrincipale) this.controllo.getVista().getSottovista(Costanti.
VISTA_PANNELLO_PRINCIPALE);
Teatro t = (Teatro) this.controllo.getModello().getBean(Costanti.TEATRO);
Iterator i = t.getListaPosti().iterator();
while(i.hasNext()){
Posto posto = (Posto) i.next();
if(posto.isStato() == true){
int selezione = p.getSelectedIndex();
if(selezione != -1){
posto = t.getPosto(selezione);
if(posto.isStato() == false){
messaggio += "Posto gia' occupato\n";
this.controllo.getVista().finestraMessaggi(messaggio);
return;
}
this.controllo.getModello().putBean(Costanti.POSTO, posto);
FinestraSpettatore fs = (FinestraSpettatore) this.controllo.getVista().
getSottovista(Costanti.VISTA_FINESTRA_SPETTATORE);
fs.setVisible(true);
return ;
}
else{
messaggio += "Non hai selezionato nulla\n";
this.controllo.getVista().finestraMessaggi(messaggio);
}
}
}
messaggio += "Non ci sono posti disponibili\n";
this.controllo.getVista().finestraMessaggi(messaggio);
System.exit(0);
}
}
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package it.unibas.teatro.controllo;
import
import
import
import
import
import
import
import
import
import
import
it.unibas.teatro.Costanti;
it.unibas.teatro.modello.Modello;
it.unibas.teatro.modello.Teatro;
it.unibas.teatro.persistenza.DAOTeatro;
it.unibas.teatro.persistenza.IDAOTeatro;
it.unibas.teatro.vista.Vista;
java.util.HashMap;
java.util.Map;
javax.swing.Action;
org.apache.commons.logging.Log;
org.apache.commons.logging.LogFactory;
public class Controllo {
private Vista vista;
private Modello modello;
private Map mappaAzioni = new HashMap();
private Log logger = LogFactory.getLog(Controllo.class);
public Controllo() {
this.inizializzaAzioni();
this.modello = new Modello();
this.caricaArchivio();
this.vista = new Vista(this, modello);
}
public void inizializzaAzioni(){
this.mappaAzioni.put(Costanti.AZIONE_ESCI, new AzioneEsci(this));
this.mappaAzioni.put(Costanti.AZIONE_ACQUISTA_BIGLIETTO, new AzioneAcquistaBiglietto(
this));
this.mappaAzioni.put(Costanti.AZIONE_INVIA, new AzioneInvia(this));
this.mappaAzioni.put(Costanti.AZIONE_INIZIA_ACQUISTO, new AzioneIniziaAcquisto(this));
this.mappaAzioni.put(Costanti.AZIONE_RICERCA, new AzioneRicercaPostoSpettatore(this));
this.mappaAzioni.put(Costanti.AZIONE_VISUALIZZA_TABELLA_BIGLIETTI, new
AzioneVisualizzaTabellaBiglietti(this));
}
public Action getAzione(String nome){
return (Action) this.mappaAzioni.get(nome);
}
public void caricaArchivio(){
IDAOTeatro daoTeatro = new DAOTeatro();
try{
Teatro teatro = (Teatro) daoTeatro.carica("");
this.getModello().putBean(Costanti.TEATRO,teatro);
}catch(Exception e){
logger.error("Errore nel caricamento!!" + e);
}
}
public Vista getVista() {
return vista;
}
public void setVista(Vista vista) {
this.vista = vista;
}
public Modello getModello() {
return modello;
}
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public void setModello(Modello modello) {
this.modello = modello;
}
public Map getMappaAzioni() {
return mappaAzioni;
}
public void setMappaAzioni(Map mappaAzioni) {
this.mappaAzioni = mappaAzioni;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Controllo controllo = new Controllo();
}
});
}
}
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package it.unibas.teatro.modello;
import java.util.HashMap;
import java.util.Map;
public class Modello {
private Map mappaBean = new HashMap();
public Modello() {
}
public Object getBean(String nome){
return this.mappaBean.get(nome);
}
public void putBean(String nome , Object bean){
this.mappaBean.put(nome,bean);
}
}
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package it.unibas.teatro.vista;
import
import
import
import
it.unibas.teatro.Costanti;
it.unibas.teatro.controllo.Controllo;
it.unibas.teatro.modello.Modello;
it.unibas.teatro.modello.Teatro;
public class PannelloPrincipale extends javax.swing.JPanel {
private Vista vista;
private Controllo controllo;
private Modello modello;
public PannelloPrincipale(Vista vista) {
this.vista = vista;
this.modello = vista.getModello();
this.controllo = vista.getControllo();
initComponents();
this.visualizzaTabella();
this.inizializzaBottoni();
}
public Controllo getControllo() {
return controllo;
}
public void setControllo(Controllo controllo) {
this.controllo = controllo;
}
public Modello getModello() {
return modello;
}
public void setModello(Modello modello) {
this.modello = modello;
}
public void visualizzaTabella(){
Teatro teatro = (Teatro) this.controllo.getModello().getBean(Costanti.TEATRO);
ModelloTabella mt = new ModelloTabella(teatro);
this.tabellaPosti.setModel(mt);
}
public int getSelectedIndex(){
return this.tabellaPosti.getSelectedRow();
}
public void inizializzaBottoni(){
this.bottoneVisualizza.setAction(this.controllo.getAzione(Costanti.
AZIONE_ACQUISTA_BIGLIETTO));
}
private void initComponents() {
labelRegistra = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
tabellaPosti = new javax.swing.JTable();
labelTeatro = new javax.swing.JLabel();
bottoneVisualizza = new javax.swing.JButton();
labelRegistra.setText("REGISTRA ACQUISTO BIGLIETTO");
tabellaPosti.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(tabellaPosti);
labelTeatro.setText("TEATRO DON BOSCO");
bottoneVisualizza.setText("Visualizza");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 375, org.jdesktop.
layout.GroupLayout.PREFERRED_SIZE)
.add(labelRegistra)
.add(labelTeatro)
.add(bottoneVisualizza))
.addContainerGap(15, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(labelTeatro)
.add(20, 20, 20)
.add(labelRegistra)
.add(30, 30, 30)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.
layout.GroupLayout.PREFERRED_SIZE)
.add(32, 32, 32)
.add(bottoneVisualizza)
.addContainerGap(90, Short.MAX_VALUE))
);
}
private javax.swing.JButton bottoneVisualizza;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labelRegistra;
private javax.swing.JLabel labelTeatro;
private javax.swing.JTable tabellaPosti;
}
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package it.unibas.teatro.vista;
import
import
import
import
import
import
it.unibas.teatro.Costanti;
it.unibas.teatro.controllo.Controllo;
it.unibas.teatro.modello.Modello;
java.util.HashMap;
java.util.Map;
javax.swing.JOptionPane;
public class Vista extends javax.swing.JFrame {
private Controllo controllo ;
private Modello modello;
private Map mappaSottoviste = new HashMap();
public Vista(Controllo controllo,Modello modello){
this.modello = modello;
this.controllo = controllo;
initComponents();
this.inizializzaMenu();
this.inizializzaSottoviste();
this.postComponent();
}
public void postComponent(){
this.pack();
this.setVisible(true);
}
public void inizializzaMenu(){
this.esci.setAction(this.getControllo().getAzione(Costanti.AZIONE_ESCI));
this.acquistaBiglietto.setAction(this.controllo.getAzione(Costanti.AZIONE_INIZIA_ACQUISTO
));
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
this.ricercaPostoCliente.setAction(this.controllo.getAzione(Costanti.AZIONE_RICERCA));
}
public Object getSottovista(String nome){
return this.mappaSottoviste.get(nome);
}
public void inizializzaSottoviste(){
PannelloPrincipale pp = new PannelloPrincipale(this);
this.mappaSottoviste.put(Costanti.VISTA_PANNELLO_PRINCIPALE,pp);
FinestraSpettatore fs = new FinestraSpettatore(this);
this.mappaSottoviste.put(Costanti.VISTA_FINESTRA_SPETTATORE,fs);
RicercaPosto rp = new RicercaPosto(this);
this.mappaSottoviste.put(Costanti.VISTA_RICERCA_POSTO,rp);
Biglietti b = new Biglietti(this);
this.mappaSottoviste.put(Costanti.VISTA_BIGLIETTI,b);
}
public Controllo getControllo() {
return controllo;
}
public void setControllo(Controllo controllo) {
this.controllo = controllo;
}
public Modello getModello() {
return modello;
}
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
public void setModello(Modello modello) {
this.modello = modello;
}
public void finestraMessaggi(String messaggio){
JOptionPane op = new JOptionPane();
op.showMessageDialog(this,messaggio);
}
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
esci = new javax.swing.JMenuItem();
acquistaBiglietto = new javax.swing.JMenuItem();
ricercaPostoCliente = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Teatro");
jMenu1.setText("File");
esci.setText("Item");
jMenu1.add(esci);
acquistaBiglietto.setText("Item");
jMenu1.add(acquistaBiglietto);
ricercaPostoCliente.setText("Item");
jMenu1.add(ricercaPostoCliente);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
pack();
}
private
private
private
private
private
javax.swing.JMenuItem acquistaBiglietto;
javax.swing.JMenuItem esci;
javax.swing.JMenu jMenu1;
javax.swing.JMenuBar jMenuBar1;
javax.swing.JMenuItem ricercaPostoCliente;
}
C:\Documents and Settings\Power\Desktop\Materiale Esperimento Potenza\codice teatro\codice teatro + class diagram\source code_acquistoConInsuccesso\Vista.java — F
Scarica