Task 7 of 7 · 0 solved · 7 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

Problem

11.1 Enums — capstone: coins with data

Write a complete program with an enum Coin whose constants carry their value in cents: PENNY(1), NICKEL(5), DIME(10), QUARTER(25). Give it a field, a constructor and a getter.

Read a count and then that many coin names. Print the total value, then how many kinds of coin the enum has.

For 3 then QUARTER DIME PENNY:

36
4

Coin.valueOf(name) turns the text into a constant, and Coin.values().length counts them.

time 1000 ms memory 256 Mb
Solution
Attempts: 0 A hint guides you to the fix — it never writes the code for you.
✦
Ready to check

Press «Submit» to run your code against the task's test cases — that is what sets your score. «AI review» is an optional second opinion: it reads your code — logic and style, not just the output — and suggests the next step without handing over the answer. It never changes your score.

Next module →
Working…