Loading...
Loading...
Loading...
A child empties a piggy bank. Declare enum Coin with ONE(1), TWO(2), FIVE(5), TEN(10) and TWENTY(20), a private final value and a getter. Count the coins of each kind and print every kind that appears, in the enum's order, then the total.
COIN x count = Rs. amount for each kind with at least one coin, then Total: Rs. total.Example
Input
5 TEN ONE TEN TWENTY ONE
Output
ONE x 2 = Rs. 2 TEN x 2 = Rs. 20 TWENTY x 1 = Rs. 20 Total: Rs. 42
ONE comes first in the enum, so it is printed first.
Try the problem first. Open one hint at a time.
Keep int[] count = new int[Coin.values().length]; and add 1 at c.ordinal().
Loop over Coin.values() to print in declaration order.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor