Loading...
Loading...
A shop bill has normal products and products on sale. A sale takes a percentage off the price; the discount is rounded down to whole rupees.
Write Product (private name and price, long finalPrice()) and DiscountedProduct extends Product (adds percent) whose finalPrice() subtracts the discount from super.finalPrice().
P name price or D name price percent.name finalPrice, with (p% off) added for a discounted product, then TOTAL sum.Example
Input
3 P pen 20 D bag 999 15 P book 250
Output
pen 20 bag 850 (15% off) book 250 TOTAL 1120
15% of 999 is 149.85, rounded down to 149, so the bag costs 850.
Try the problem first. Open one hint at a time.
The discount is price × percent / 100 in whole numbers, which already rounds down.
Inside the child, super.finalPrice() gives the normal price without touching the private field.
Add each final price to a long total.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor