Question: Question 1 [ 2 0 marks ] You are building an e - commerce application for a store that sells various products. Each product has
Question
marks
You are building an ecommerce application for a store that sells various products.
Each product has attributes like name, price, and quantity. Products are categorised
as clothing, electronics, and books. There are also ongoing category discounts
percentage off that apply to all products within that category.
Instructions:
Product Class: Define a class named Product with the following properties:
name string
price float
quantity integer
Category Class: Define a class named Category with the following properties:
name string
discount float percentage between and
DiscountedProduct Class: Create a class named DiscountedProduct that
inherits from the Product class. It should have an additional property:
category object of the Category class
Multidimensional Array: Create a multidimensional array named $products
where the first dimension represents categories keys are category names and
the second dimension is an array of DiscountedProduct objects belonging to that
category.
Discount Application: Write a function named calculateDiscountedPrice that
takes a DiscountedProduct object as input. It should calculate the final price after
applying the category discount as follows:
Final price price category.discount
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
