โ Back to Polymorphism
Question 573
Discount Strategies
Discount Strategies
Build an interface-based strategy from scratch. Define an interfaceIDiscountwith a methodint Apply(int price). Then define two classes that implement it: -PercentOff(int percent)whoseApplyreturnsprice - price * percent / 100-FlatOff(int amount)whoseApplyreturnsprice - amountThe tester applies each strategy to a price of200. Do NOT write aMainmethod. ForPercentOff(10)thenFlatOff(15)on200the program prints: 180 185
Expected Output:
180 185
Topics:
Polymorphism
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.