CJCoding With Joseph
15free / daySign inCreate account

Discount is an abstract class: apply(double price) returns the price after the discount, and each kind of discount works it out differently. Write both subclasses.

Requirements: 1. PercentDiscount has a public constructor PercentDiscount(double percent). Its apply takes that percentage off the price, so 25 percent off 80.0 gives 60.0. 2. FlatDiscount has a public constructor FlatDiscount(double amount). Its apply subtracts the amount from the price, and returns 0.0 when the amount is larger than the price. 3. Each class stores its number in a private field. 4. PercentDiscount is the public class. Keep FlatDiscount without the word public, because a Java source file may contain only one public class.

Do not change the Discount class. Its receipt method calls your apply.

Do NOT write a main method.

Expected output

80.00 -> 60.00
80.00 -> 65.00

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
Abstract ClassesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.