Johan Mena wrote:In CombinedDiscount's version of computeDiscount, should I call BulkDiscount and BuyNGetOneFree version of computeDiscount and then return the largest discount?
Yes, that's exactly what the instructions say:
Johan Mena wrote:Derive CombinedDiscount from DiscountPolicy, as described in Exercise 10. It should have a constructor that has two parameters of type DiscountPolicy. It should define the method computeDiscount to return the maximum value returned by computeDiscount for each of its two private discount policies.: BulkDiscount and BuyNItemsGetOneFree.
Johan Mena wrote:If so, how would I call those methods from this sibling (?) class? Will I have to create a temp object from each of those classes and then call the methods using those objects?
No, why do you think you have to create a temporary object? You already have references to the two other discounts, in the member variables
first and
second. You can just call the
computeDiscount method on those two, and then return the largest of the two answers.
Do you understand how to call a method on an object? It's just: variable name, dot, method name, arguments: