Question
please use textpad, thank you here's the coin class:- /**************************************** * Coin.java * * Represents a coin that can be flipped ****************************************/public class Coin {private
please use textpad, thank you
here's the coin class:-
/**************************************** * Coin.java * * Represents a coin that can be flipped ****************************************/public class Coin {private final int HEADS = 0; //tails is 1private int face; // current side showing/****************************** * sets up coin by flipping it * ****************************/public Coin() {flip();}/****************************** * set a random face value * ****************************/public void flip() {face = (int) (Math.random()*2);}/************************************* * returns true if the current face * value is heads and false otherwise * ***********************************/public boolean isHeads() {return (face == HEADS);}/****************************** * return current face value * ****************************/public String toString() {String result;if(face == HEADS)result = "Heads";elseresult = "Tails";return result;}}
Design and implement a class called MonetaryCoin that is derived from the given Coin class. Store a value in the monetary coin that represents its value and add a method that returns its value. Create a driver that instantiates and computes the sum of several MonetaryCoin objects and demonstrate that a monetary coin inherits its parent's ability to be flipped
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started