Search⌘ K
AI Features

Completing the Definition of the Class Coin

Explore how to finish defining the Coin class by implementing constructors that use randomization and enumerations to represent coin types. Understand how to manage data fields such as value and year, and learn best practices for constructor design and method usage to create a robust class representing coins.

Often a good problem-solving strategy is to solve a somewhat simpler problem that we can enhance to solve the original problem. Recall that we defined the class Coin1 as a step towards the class Coin. The previous lesson shows the definition of this simpler class.

Revising the constructor

We decided in the previous lesson to have Coin1’s default constructor create a heads-up coin. ...