DU Programming Project
Description
Q1 (06 marks) Let us suppose that you are designing an e-commerce application for an ABC
company. The company keeps a detailed record and offers a loyalty card to each of its customers.
The customers can accumulate loyalty points through their purchases and can also get discounts
based on their loyalty points. Now, you are trying to design a class to represent these customers.
Your highly productive partner already designed a class called Customer using the provided interface
ICustomer. However, currently, the class does not follow the single responsibility principle (SRP),
which leads to several unexpected issues. For example, discount rate cannot be changed without
modifying the code from Customer class, which is undesirable. To solve this issue, you will use
an attribute (or delegate) namely Membership to the customer entity where the membership is
connected to a discount calculation rule. Using this attribute, you will move the business logic of
calculating discount to elsewhere and thus will make sure that every class follows SRP. (Remember
the salary calculation example from Lecture 11 on SOLID principles). Please do the following.
Run CustomerTest class and see the testCustomer() method to pass
and the testCustomerWithSRP() method to fail.
The assignment code contains an incomplete, buggy implementation of CustomerSRP,
Membership and DiscountCalculator. The testCustomerWithSRP() method is also not
passing. Add the missing code to these three classes so that each of them follows the single responsibility principle (SRP). The modified code should pass all the tests from the
CustomerTest class. Once done, make a separate commit with an appropriate message to
GitLab and attach a screenshot of the passing tests to the answer PDF (06 marks).
Q2 (06 marks): Let us suppose that ABC superstore wants you to design a loyalty card application. Each of its customers owns a card that is loaded with a few loyalty points. The customers can
accumulate more points through their purchases. The application should allow the customers to
(a) convert their loyalty points into cash, (b) transfer their points to another card, and (c) buy the
fresh produce from the store. Interestingly, ABC has an old, incomplete version of the application
called LoyaltyCard that implements the first two requirements. However, it does not follow the
open/closed principle (OCP), which leads to several issues. For example, LoyaltyCard cannot be
extended without modifying its code or behaviour, which could be risky. You will design a new
version namely SmartLoyaltyCard that implements all three requirements above and follows OCP.
That is, one should be able to extend SmartLoyaltyCard application (e.g., adding another benefit
for the customers) later without modifying its code. (Remember the example of CloudPersistence
from Lecture 11). Please do the following.
Run LoyaltyCardTest class and see the testOldCardOperations() method to pass
and the rest test methods to fail.
The assignment code contains an incomplete, buggy implementation of SmartLoyaltyCard,
CashInTransaction, TransferTransaction and BuyProduceTransaction, and the corresponding test methods are not currently passing. Add the missing code to these four classes
and ensure that SmartLoyaltyCard follows the open/closed principle (OCP). The new code
should pass all the tests from LoyaltyCardTest class. Once done, make a separate commit
with an appropriate message to GitLab and attach a screenshot of the passing tests to the
answer PDF (06 marks).
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."