Question

Implement a class to represent a cash register. At the start of each transaction, the amount...

  1. Implement a class to represent a cash register. At the start of each transaction, the amount due from the customer is $0.00. As items are scanned, the amount due increases. The cash register should be able to report the current amount due at any time. Your class should implement the following methods:

               startTransaction(self) Sets the current transaction total to 0.00.

               addItem(self, amount) Adds the given amount to the total.

                                   

               total(self) Returns the total amount due so far.

Provide test cases by writing code to simulate three transactions with items of varying amounts.

Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

class cash_register:

   

               def __init__(self):          #define construtor

                              self.totall = 0.00

                             

               def startTransaction(self): #Sets the current transaction total to 0.00

                              self.totall = 0.00

               def addItem(self, amount):   #Adds the given amount to the total.

                              self.totall += amount

               def total(self):           #Returns the total amount due so far.

                              return (self.totall)

                             

b = cash_register()

b.startTransaction()

b.addItem(10.6)

b.addItem(5.7)

b.addItem(4.0)

b.addItem(10)

a = b.total()

print(a)

b.startTransaction()

b.addItem(4.7)

b.addItem(45.0)

b.addItem(76.9)

a = b.total()

print(a)

b.startTransaction()

b.addItem(45.0)

b.addItem(56.9)

a = b.total()

print(a)

Output:

Add a comment
Know the answer?
Add Answer to:
Implement a class to represent a cash register. At the start of each transaction, the amount...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...

    Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed in class. Once complete, test the class using the CashRegisterTester class. Make sure you have 3 total items in the cash register. I have two classes, the first is CashRegisterTester below: public class CashRegisterTester { public static void main(String[] args) { //Initialize all variables //Construct a CashRegister object CashRegister register1 = new CashRegister(); //Invole a non-static method of the object //since it is non-static,...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Please implement the following only using Javascript. design a cash register class that can be used...

    Please implement the following only using Javascript. design a cash register class that can be used with inventory item class. The cash register class needs to: 1. ask user for item and quantity being purchased. 2. get the items cost from inventory item object 3. add 30% profit to the cost to get the items unit price 4. multiply the unit price times the quantity being purchased to get purchase subtotal 5. compute a 6% sales tax on the subtotal...

  • Write code in Java programming language. The ShoppingCart class will be composed with an array of...

    Write code in Java programming language. The ShoppingCart class will be composed with an array of Item objects. You do not need to implement the Item class for this question, only use it. Item has a getPrice() method that returns a float and a one-argument constructor that takes a float that specifies the price. The ShoppingCart class should have: Constructors: A no-argument and a single argument that takes an array of Items. Fields: • Items: an array of Item objects...

  • need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class si...

    need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

  • DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress,...

    DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress, Cart and Main. ITEM CLASS Your Item class should contain: Attributes (protected) String name - name of the Item double price - price of the item Methods (public) void setName(String n) - sets the name of Item void setPrice(double p) - sets the price of Item String getName() - retrieves name double getPrice() - retrieves price String formattedOutput() returns a string containing detail of...

  • implement a class called PiggyBank that will be used to represent a collection of coins. Functionality...

    implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...

  • Module 6 - Cash Register (10 Points) We are going to write a program that simulates...

    Module 6 - Cash Register (10 Points) We are going to write a program that simulates a customer's transaction at a cash register. You will organize your code using functions. Each of the functions below counts for 2 points. You must create functions allowing the user to: 1. Add an item to the order. No name or list of items is needed simply prompt the user for a dollar amount to add. 2. Clear all transactions. Set the amount of...

  • Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores...

    Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores the individual cards that are dealt (i.e. cannot just store the sum of the cards, you need to track which specific cards you receive) Provided methods: decide_hit(self): decides whether hit or stand by randomly selecting one of the two options. Parameters: None Returns: True to indicate a hit, False to indicate a stand Must implement the following methods: Hi!! i just need help with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT