Question: Python Programming: For the assignment you must define and implement the Item class so that the code shown immediately below can produce the result shown
Python Programming:
"For the assignment you must define and implement the Item class so that the code shown immediately below can produce the result shown below that. You will need to define the four private variables of the Item class for the price, weightInOunces , description, and quantity.
You are to include a constructor (__init__), that takes three input parameters for the price, weightInOunces, and description, but not quantity which should be set to a default value of 1
You will also need to create the remaining methods that are used in the code below the gets and sets. The contents of the main function and the output are shown below. Copy, and do not change, the code below. Pay close attention to the values in the output. If you do not match the details correctly, some of your values will not be the same as those shown. (Hint: Theres a reason that the getOrderPrice() method is not called getPrice() and in the example it affects the order for glasses.) "
def main():
dTotalPrice = 0.0
iTotalWeight = 0
# Put the 4 items being ordered in item1 through item 4
item1 = Item.Item(24.99, 14, "Wireless Mouse")
item2 = Item.Item(22.49, 27, "USB Keyboard")
item3 = Item.Item(24.99, 12, "HDMI Cable")
item4 = Item.Item(7.99, 7, "Reading Glasses")
item4.set_quantity(2);
# Show the details of the order using show()
print("Here are your shopping cart contents.")
print(item1);
print(item2);
print(item3);
print(item4);
# Compute the total price and total weight in this section
dTotalPrice += item1.getOrderPrice()
dTotalPrice += item2.getOrderPrice()
dTotalPrice += item3.getOrderPrice()
dTotalPrice += item4.getOrderPrice()
iTotalWeight += item1.getOrderWeightInOunces()
iTotalWeight += item2.getOrderWeightInOunces()
iTotalWeight += item3.getOrderWeightInOunces()
iTotalWeight += item4.getOrderWeightInOunces()
# Here we show the order details
print("The price of your order is $" + str(dTotalPrice));
print("The shipping weight is", (int)(iTotalWeight / 16),
"pounds", iTotalWeight % 16 , "ounces");
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
