Program kasir dengan Python kelas
1##
2# This module defines the CashRegister class.
3#
4
5## A simulated cash register that tracks the item count and the total amount due.
6#
7class CashRegister :
8 ## Constructs a cash register with cleared item count and total.
9 #
10 def __init__(self) :
11 self._itemCount = 0
12 self._totalPrice = 0.0
13
14 ## Adds an item to this cash register.
15 # @param price the price of this item
16 #
17 def addItem(self, price) :
18 self._itemCount = self._itemCount + 1
19 self._totalPrice = self._totalPrice + price
20
21 ## Gets the price of all items in the current sale.
22 # @return the total price
23 #
24 def getTotal(self) :
25 return self._totalPrice
26
27 ## Gets the number of items in the current sale.
28 # @return the item count
29 #
30 def getCount(self) :
31 return self._itemCount
32
33 ## Clears the item count and the total.
34 #
35 def clear(self) :
36 self._itemCount = 0
37 self._totalPrice = 0.0
Deron21