Question: Problem 1 .Design and implement a class called MonetaryCoin that is derived from the Coin class presented in Chapter 5 (see below). Store an int

Problem 1.Design and implement a class called MonetaryCoin that is derived from the Coin class presented in Chapter 5 (see below). Store an int value in the monetary coin that represents its value in cents, add getter and setter methods for the monetary value as well as a toString method (override) to return the monetary value and face. //******************************************************************** // Coin.java Author: Lewis/Loftus // Solution to Programming Project 5.6 // Represents a coin with two sides that can be flipped. //******************************************************************** public class Coin { private final int HEADS = 0; private final int TAILS = 1; private int face; // // Sets up the coin by flipping it initially. // public Coin () { flip(); } // // Flips the coin by randomly choosing a face value. // public void flip () { face = (int) (Math.random() * 2); } // // Returns true if the current face of the coin is heads. // public boolean isHeads () { return (face == HEADS); } // // Returns the current face of the coin as a string. // public String toString() { String faceName; if (face == HEADS) faceName = "Heads"; else faceName = "Tails"; return faceName; } } Problem 2. Crreate a main driver class to instantiate 30 monetary coins (use an array for this) with random monetary values. The driver flips all the coins, computes, and prints to the screen the total monetary value of all the coins with HEADS face.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!