Resolve this java code class Coin { private final int HEADS = 0; private final int TAILS
Fantastic news! We've Found the answer you've been seeking!
Question:
Resolve this java code
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; }}class MonetaryCoin1 extends Coin { int value; // Returns value of MonetaryCoin. public int getValue() { return value; }}public class MonetaryCoin { public static void main(String[] args) { MonetaryCoin1 coin1 = new MonetaryCoin1(); coin1.value = 5; System.out.println("Value of coin1 is: " + coin1.getValue()); MonetaryCoin1 coin2 = new MonetaryCoin1(); coin2.value = 10; System.out.println("Value of coin2 is: " + coin2.getValue()); MonetaryCoin1 coin3 = new MonetaryCoin1(); coin3.value = 1; System.out.println("Value of coin3 is: " + coin3.getValue()); System.out.println("Sum of all coins is: " + (coin1.getValue() + coin2.getValue() + coin3.getValue())); System.out.println("coin1 is: " + coin1.toString()); coin1.flip(); System.out.println("After flip coin1 is: " + coin1.toString()); }}
so above is my code and my expected output is suppose to be
Heads1?Heads5?Heads10?Heads25?Heads50?Tails100?Tails100??TotalValue:291?
But the actual output I get is
Valueofcoin1is:5?Valueofcoin2is:10?Valueofcoin3is:1?Sumofallcoinsis:16?coin1is:Tails?Afterflipcoin1is:Heads?
What part of my code would I need to change to get the desired output, I'm confused. Also note I have MonetaryCoin and MonetaryCoin1 there is a difference. Below is the original question if its of any help
Related Book For
Posted Date: