Instructions
Requirements and Specifications
- For this assignment, refer to page 425 of your textbook. Complete assignment 10.10 and create the Invoice class as per instruction. (30 points)
- Once you have written the class, write a program that creates two Invoice Objects to hold the following data: (30 points)
Part Num | Description | Quantity | Price | Total |
1001 | Hammer 20 | 15 | 300 | |
1001 | locks | 15 | 5 | 75 |
- The program should store this data in the two objects, then display the object information in the manner shown in the table above , note that the total is NOT hardcoded, it’s calculated based on the item’s quantity and price (25 points)
Submit your finished code solution file(s) through the assignment link below:
Note: Write program Pseudocode (detail algorithm) and add it as a comment block to the submitted program. (15 points).
Screenshots
Source Code
# A brief description of the project
# Date
# CSC121 M8Pro – Invoice Class
# Your Name
class Invoice:
def __init__(self, number, description, quantity, price):
self.number = number
self.description = description
self.quantity = quantity
self.price = price
def get_number(self):
return self._number
def set_number(self, value):
self._number = value
def get_description(self):
return self._description
def set_description(self, value):
self._description = value
def get_quantity(self):
return self._quantity
def set_quantity(self, value):
self._quantity = value
def get_price(self):
return self._price
def set_price(self, value):
self._price = value
def calculate_invoice(self):
return self.price * self.quantity
number = property(get_number, set_number)
description = property(get_description, set_description)
quantity = property(get_quantity, set_quantity)
price = property(get_price, set_price)
def main():
"""
Algorithm:
1. Creating to invoice objects for given invoice parameters
2. Print header, using python string formatting with 15 chars per column
3. Print invoice #1 parameters, using python string formatting with 15 chars per column. Total amount is calculated
by calculate_invoice() instance method3.
4. Print invoice #2 parameters, using python string formatting with 15 chars per column. Total amount is calculated
by calculate_invoice() instance method
"""
i1 = Invoice('1001', 'Hammer', 20, 15.0)
i2 = Invoice('1002', 'locks', 15, 5.0)
print('{:<15}'.format('Part Num'), '{:<15}'.format('Description'), '{:<15}'.format('Quantity'),
'{:<15}'.format('Price'), '{:<15}'.format('Total'), sep='')
print('---------------------------------------------------------------------------')
print('{:<15}'.format(i1.number), '{:<15}'.format(i1.description), '{:<15}'.format(str(i1.quantity)),
'{:<15}'.format(str(i1.price)), '{:<15}'.format(str(i1.calculate_invoice())), sep='')
print('{:<15}'.format(i2.number), '{:<15}'.format(i2.description), '{:<15}'.format(str(i2.quantity)),
'{:<15}'.format(str(i2.price)), '{:<15}'.format(str(i2.calculate_invoice())), sep='')
print('---------------------------------------------------------------------------')
if __name__ == '__main__':
main()