Professional Documents
Culture Documents
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
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
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
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&/
1&1
randomShopping
'dd a pri#ate operation randomShopping to the Tester class.
1&2
1&3
1&4
Extended exercise
'dd a new +e)uence !iagram Ticket as follows1 :nsure that the ;ame is *.
1&5
1&6
1&7