Assignment Part 1 Details – Class Design Think of a product that you can buy fro
ID: 3714905 • Letter: A
Question
Assignment Part 1 Details – Class Design Think of a product that you can buy from a supermarket, like maybe a can of soup or an apple. Start by listing all the properties of that object that you can think of – try to come up with at least ten general properties of a Product and write these down in your Assignment_Part_1_ Microsoft Word document. Next, use the process of abstraction to cut the number of properties back to only four ‘key’ properties – write these down in the next section of your Word document. Take a look at the week 2 lecture slides if you need a reminder on how to go about this. Now, fill in the class diagram for your Product class in the Word document template provided. Your product class does not have to have any methods (i.e. functions) associated with it to perform any actions other than a constructor which takes and set the four key properties that you’ve identified. Next we’ll move on to CheckoutRegister class – think about what information the checkout has to keep track of to allow you to successfully check out of the supermarket. There will only really be three key properties that the CheckoutRegister cares about, and the CheckoutRegister class should have the following four methods available: 1) A default constructor that takes no arguments and initialises a new object and its properties, 2) accept_payment(some_amount), 3) scan_item(some_product), and 4) print_receipt(). Fill in the class diagram for the CheckoutRegister class in the Word template, and that’s the first part completed!
Explanation / Answer
Note- I've used syntax somewhat similar to C++ to write the constructor and class definitions. Please let me know if you want me to modify this for some other language. The code inside the constructor is only given for your understanding; it is usually not mentioned in Class Designs.
Also, please attach a screenshot of the Word template that the question mentions if you require help filling it with the details described below.
Ans: Properties or attributes of an object or a class are what describe the object/class. As per the question we'll start by describing an object: a can of soup.
A can of soup can have the following general properties:-
1) Name
2) Brand
3) Flavor
4) Vegan/Non-Vegan
5) Weight
6) Price
7) Date of Packaging
8) Date of Expiry
9) Manufacturer Name
All of the above properties together describe a particular can of soup. But a supermarket does not sell only soup. It sells a variety of products. The types of these products sold can increase or decrease. So when you write a program to handle the operations of the supermarket, you can't have a different class for each product. Rewriting the whole app just to add or remove a product would be too much of a hassle.
This is where abstraction comes in. Instead of having a class, say 'Soup Can' for just soups, our program can have a more general class, say, 'Product' which can be used to describe any and all products stocked by the supermarket.
The properties of this class would be:-
Product
This is a general class to describe all products in the supermarket. Some products like sodas are measured by volume rather than weight, so we have dropped the 'Weight' property from this class. We can have more specific sub-classes if required for different kinds of products,eg- soup, fruit, etc.
The constructor of this Product class can be written as:-
Product::Product(long pID, string pName, double pPrice, Date pDate){
ProductID=pID;
Name=pName;
Price=pPrice;
DateOfPackaging=pDate;
}
So the class can be written as:-
class Product{
long ProductID;
string Name;
double Price;
Date DateOfPackaging;
public:
Product(long pID, string pName, double pPrice, Date pDate);
}
Class Diagram:-
ProductID : long
Name : string
Price : double
DateOfPackaging : Date
The CheckOutRegister class can have the following properties:-
This class can be defined with its properties and methods as:-
class CheckOutRegister{
long ReceiptNo;
int NoOfItems;
double TotalPrice;
public:
CheckoutRegister(); //constructor
bool accept_payment(double amt); //returns true if payment completed successfully
bool scan_item(long productID); //takes the product ID (from bar code) as parameter and returns true on successful scan
void print_receipt(); //prints the receipt, returns nothing
}
Class Diagram:-
ReceiptNo : long
NoOfItems : int
TotalPrice : double
CheckoutRegister()
bool accept_payment(double amt)
bool scan_item(long productID)
void print_receipt()
Hope this helps!
Property Name Data Type1) Name
String2) Brand
String3) Flavor
String4) Vegan/Non-Vegan
Boolean5) Weight
Float6) Price
Double7) Date of Packaging
Date8) Date of Expiry
Date9) Manufacturer Name
String 10) Product ID (Bar Code) Long IntRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.