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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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')

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education