You are on page 1of 21

Generate a ticket use case

In order to generate a ticket, you need to be able to count how many there are of each product. To do so, you will introduce a new class CountedProduct.
Create a new O ! in the package CashRegisterPkg called "roduct O#er#iew. !raw class CountedProduct and drag Cash$egister and "roduct classes onto the diagram.

$emo#e the port from the Cash$egister in this #iew. $ight%click then select Ports > Hide All Ports.
167

CountedProduct
'dd generali(ation. 'dd )ualified association with multiplicity * 'dd attribute count of type int initiali(ed to 1 +et the property to generate an accessor for count.

16&

getPrice() / increment()
'dd operations getPrice-. and increment-..

16,

CountedProduct constructor 1
0ou will be creating CountedProducts from "roducts so you need a constructor that takes a Product as an argument with direction In. 'dd the constructor.

17/

CountedProduct constructor 2
's for the "roduct class, you do not need an implicit constructor for the Counted"roduct class. +et the following property1

171

Another product constructor


'dd another constructor to the Product class, that is public and that takes Product as an argument.

172

Adding a scenario
'dd an 'nalysis se)uence diagram entitled Scenario generating a ticket. !rag the classes from the browser onto the diagram. !ouble%click on each instance of CountedProduct to enter the specific instance name.

173

Completing the scenario


Complete the scenario and reali(e the messages.

174

print() operation
The print() operation is shown as being in#oked on the Tester class. In fact, it is being in#oked on the IPrinter Interface class. 'dd an argument aMsg of type char* to the Tester print() operation and then copy it to the Interface class IPrinter. "ress Ctrl while dragging it.

175

print() operation implementation


'dd the following implementation to the print() operation of the Tester class.

176

CountProducts operation
6or the CashRegister class, add the implementation for the operation countProducts-..

177

generateTicket() operation
6or the CashRegister class, add the implementation for the operation generateTicket-. .

17&

endSession()
0ou need to modify the endSession-. operation so that you remo#e all the CountedProducts and delete them.

17,

Printing a ticket
+a#e. 7enerate 8 ake 8 $un. 9se the !O+ console to start a session, enter some barcodes, and then end the session.

1&/

Using the tester to print a ticket


'dd a new state scenarioGeneratingTicket to the Tester class, so you can easily test out the model.

1&1

randomShopping
'dd a pri#ate operation randomShopping to the Tester class.

1&2

Executing the scenario


+a#e 8 7enerate 8 ake 8 $un +end e#ent e S! to the Tester. 8 7o.

1&3

e!erenced se"uence diagrams


'dd the se)uence diagram Scenario generating a ticket to the use case Generating a ticket sho"ing total cost.

1&4

Extended exercise
'dd a new +e)uence !iagram Ticket as follows1 :nsure that the ;ame is *.

1&5

Automatic creation o! instance lines


Close all windows. $un 8 7o. +et breakpoint. In<ect e#+3 to the Tester. =hen breakpoint reached, open animated se)uence diagram based on Ticket. 7o.

1&6

Automatic creation o! instance lines

1&7

You might also like