Question: Write a class (Product) that has three instance variables: 1. name (a string) 2. price (a floating point number) 3. weight (a floating point number)
Write a class (Product) that has three instance variables: 1. name (a string) 2. price (a floating point number) 3. weight (a floating point number) Your class should also have four member functions: 1. a constructor This function will store the values of the three instance variables, which will be passed as arguments in the order given above (see the sample output, below, for an example) 2. getShippingCost() This function will calculate the cost of shipping the item using the formula: shippingCost = weight * 10 3. getTax() This function will calculate the tax on the item (not including shipping): tax = price * 0.13 4. getTotalCost() This function will calculate the total cost of the item: totalCost = price + tax + shippingCost Note: For this class, you can use any built-in functions that youd like. Sample output: razor = Product("Electric Razor", 49.99, 0.25) homeGym = Product("Home Gym", 879.99, 115.0) print("total cost of", razor.name, ":", razor.getTotalPrice()) # 58.9887 print("total cost of", homeGym.name, ":", homeGym.getTotalPrice()) # 2144.3887
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
