In: Computer Science
Draw a UML diagram that describes a class that will be used to describe a product for sale on Glamazon.com. The product has a name, a description, a price, ratings by many customers (1 to 5 stars), and a group of customer comments. New products have no ratings or comments by customers, but do have a name, description and price. The price can be changed and more customer ratings and comments can be added. A global average rating of all customer ratings also needs to be provided. All other fields are unchangeable. Show at least one constructor.
Hint: The easiest way to draw UML diagrams in a Word document is to use a one column by 3 row table.
The UML diagram for the class Product is shown as follows:
The name of the class is Product which is shown in the first row of the diagram. The Product class will have 5 member variables which are shown as follows:
· pname: The variable pname will have the name of the product and it cannot be changed. The data type of this variable will be string of constant type because it is unchangeable.
· price: The variable price will be used to store the price of the product. The datatype of this variable will be float.
· desc: The variable desc is used to store the description of the product and its datatype is string of constant type because it is unchangeable.
· rating[]: The array rating is used to store the rating of customers between 1 and 5. This rating can be changed by any method. The return type of this variable will be integer.
· comments[]: The variable comments is used to store the comments of the customers. This is an array of string type and can be changed by any other method.
The class Product will have 5 member functions which are as follows:
· Product(name, price, description, rating, comments): It is a parameterized constructor and used to initialize the values of 5 member variables.
· Product(name, price, description): It is another parameterized constructor which is used to initialize the values of 3 member variables.
· addProduct(): This function is used to add a new product except those added by constructor. It return 1, if a new product is added, otherwise, 0.
· isNewProduct(flag): This function is used to check whether the product is new or old. If the value of flag is 1, then it means a new product is added and this function returns true.
· avgGlobalRating(rating): This function is used to calculate and return the average global rating of all the ratings given by customers.
· dispProductInfo(): This function is used to show the details of each product.