Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a class called MonetaryCoin that is derived from the Coin class. Store an integer in the MonetaryCoin that represents its value and add a
Write a class called MonetaryCoin that is derived from the Coin class. Store an integer in the MonetaryCoin that represents its value and add a method that returns its value. Create a main driver class to instantiate and compute the sum of several MonetaryCoin objects. Demonstrate that a monetary coin inherits its parents ability to be flipped.
va Author: Lewis/Loftus Represents a coin with two sides that can be flipped. public class Coin private final int HEADS o private final int TAILS 1 private int face; up the coin by flipping it initially IT public Coin) flipo the coin by randomly choosing a face value. publie void flip) (Math.random ( ) 2); face= (int) * true if the current face of the coin is heads public beolean isteads ) return (face HEADS) //.-Returns the current face of the coin as a string. publie String tostring ) String faceNane- if (face, HEADS) faceNane "Heads" faceName Tails" return faceNane 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