174k views
0 votes
Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as data attributes—a part number (a string), a part description (a string), a quantity of the item being purchased (an int) and a price per item (a Decimal). Your class should have an __init__ method that initializes the four data attributes. Provide a property for each data attribute. The quantity and price per item should each be non-negative—use validation in the properties for these data attributes to ensure that they remain valid. Provide a calculate_invoice method that returns the invoice amount (that is, multiplies the quantity by the price per item). Demonstrate class Invoice’s capabilities.

User Jnieto
by
7.7k points

1 Answer

3 votes

Final answer:

The question is about creating a class called Invoice to represent an invoice for a hardware store item.

Step-by-step explanation:

The subject of this question is Computers and Technology. The class that needs to be created is called 'Invoice.' It represents an invoice for an item sold at a hardware store. The class should have four data attributes: part number (a string), part description (a string), quantity of the item being purchased (an int), and price per item (a Decimal). The __init__ method initializes these attributes, and there should be a property for each attribute.

Validation should be used for the quantity and price per item properties to ensure they remain non-negative. The class should also have a calculate_invoice method that returns the invoice amount by multiplying the quantity by the price per item.

An example usage of the class would be creating an instance of Invoice, setting the part number, description, quantity, and price per item, and then calling the calculate_invoice method to get the total invoice amount.

User Superfly
by
7.7k points

No related questions found