CJCoding With Joseph
15free / daySign inCreate account

Write the abstract class Beverage from scratch. It knows the name of a drink, but only a subclass knows the price, so price() is abstract. label() is a finished method that still calls price(): whichever subclass the object really is supplies the number.

Requirements: 1. A private String field name, set by a public constructor Beverage(String name). 2. getName() returns the name. 3. price() is a public abstract method that takes no parameters and returns a double. 4. label() returns the name, a colon, a space, a dollar sign and the price with exactly two decimals, for example Mocha: $4.10. String.format("%.2f", ...) gives two decimals. 5. The tests bring their own subclasses, Latte and Tea. Each calls your constructor with super(...) and overrides price().

Do NOT write a main method.

Expected output

Latte
Latte: $5.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.