Place the CashRegister calss in a file called cashregister.py and write following test code in the cell below. a Complete following test code: Import all methods of CashRegister class Write a test function to test the getTotal() and getCount() methods as it follows. add 5 items. undo the last item. add 3 more items. undo the last item after your test has done all of the above, print an statement for expected total price and total count. call the getTotal() and getCount(). (the result must be equal to the previous part)
Place the CashRegister calss in a file called cashregister.py and write following test code in the cell below.
a Complete following test code:
- Import all methods of CashRegister class
- Write a test function to test the getTotal() and getCount() methods as it follows.
- add 5 items.
- undo the last item.
- add 3 more items.
- undo the last item
- after your test has done all of the above, print an statement for expected total price and total count.
- call the getTotal() and getCount(). (the result must be equal to the previous part)
class CashRegister:
def __init__(self):
self._itemCount=0
self._totalPrice=0.0
self._taxPercent=13
def addItem(self,price):
self._itemCount=self._itemCount+1
self._totalPrice=self._totalPrice+price
def getTotal(self):
return self._totalPrice
def getCount(self):
return self._itemCount
def clear(self):
self._itemCount=0
self._totalPrice=0
def updateTaxRate(self,newTaxPercent):
if newTaxPercent>1.0 and newTaxPercent<20.0:
self._taxPercent=newTaxPercent
return True
return False
def getTotalWithTax(self):
return self._totalPrice+(self._totalPrice*(self._taxPercent/100))
def itemName(self, Name):
item_name = []
def __init__(self):
self._itemCount = 0
self._totalPrice = 0.0
self._taxPercent = 13
self._item_name = []
self._item_price = []
def addItem(self,name,price):
if name not in self._item_name:
self._item_name.append(name)
self._item_price.append(price)
self._totalPrice += price
self._itemCount += 1
def getTotal(self):
return self._totalPrice
def getCount(self):
return self._itemCount
def clear(self):
self._itemCount = 0
self._totalPrice = 0
self._item_name = []
self._item_price = []
def updateTaxRate(self,newTaxPercent):
if newTaxPercent>1.0 and newTaxPercent<20.0:
self._taxPercent = newTaxPercent
return True
return False
def getTotalWithTax(self):
return self._totalPrice+(self._totalPrice*(self._taxPercent/100))
def printReceipt(self):
print('\n---------------------------------')
print('--------------RECEIPT------------')
for i in range(len(self._item_name)):
print('%-15s %10.2f'%(self._item_name[i],self._item_price[i]))
print('%-15s %10.2f'%('Total',self._totalPrice))
print('%-15s %10.2f'%('Total(inc. Tax)',self.getTotalWithTax()))
print('---------------------------------\n')
Step by step
Solved in 4 steps with 1 images