Loading...
Loading...
Loading...
A pizza counter types orders by hand, in any case. Declare enum Size { SMALL(199), MEDIUM(349), LARGE(499) } and enum Crust { THIN(0), PAN(49), CHEESE_BURST(99) }, each with a private final price.
For every order line, turn the size and crust into constants safely. A line with an unknown size or crust is skipped with a message.
SIZE CRUST x q = Rs. amount, where amount = (size price + crust price) × q. For a bad line: Line i: invalid item (i from 1). Last line: Total: Rs. total.Example
Input
3 medium pan 2 Large Thin 1 small stuffed 1
Output
MEDIUM PAN x 2 = Rs. 796 LARGE THIN x 1 = Rs. 499 Line 3: invalid item Total: Rs. 1295
stuffed is not a crust, so line 3 is skipped.
Try the problem first. Open one hint at a time.
Size.valueOf(word.toUpperCase()) throws IllegalArgumentException for an unknown word.
Put both valueOf calls in one try, so either bad word skips the line.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor