/ch09/cashregister.py
Python | 37 lines | 14 code | 5 blank | 18 comment | 0 complexity | 2242c5c604e1ab765a0a94844a00715e MD5 | raw file
- ##
- # This module defines the CashRegister class.
- #
- ## A simulated cash register that tracks the item count and the total amount due.
- #
- class CashRegister :
- ## Constructs a cash register with cleared item count and total.
- #
- def __init__(self) :
- self._itemCount = 0
- self._totalPrice = 0.0
-
- ## Adds an item to this cash register.
- # @param price the price of this item
- #
- def addItem(self, price) :
- self._itemCount = self._itemCount + 1
- self._totalPrice = self._totalPrice + price
-
- ## Gets the price of all items in the current sale.
- # @return the total price
- #
- def getTotal(self) :
- return self._totalPrice
-
- ## Gets the number of items in the current sale.
- # @return the item count
- #
- def getCount(self) :
- return self._itemCount
- ## Clears the item count and the total.
- #
- def clear(self) :
- self._itemCount = 0
- self._totalPrice = 0.0