Creating a class and Method for a coin flip

I am doing a practice problem that deals with the flipping of a coin. I understand every other step, but I am confused at how to first setup the method and class. I am confused with the variables that they have given me. The question aks, Define a class Coin with 2 instance data, a string face, which can be “heads” or “tails” and an int value that represents the monetary value of the coin. The following method should be included in the class: - a default constructor - a constructor that takes 2 parameters to initialize instance data So my question to everyone is how would I go about creating this? This is what I have so far: public class Coin { private int Value; private String Face; public Coin(int a) { Value = a; Face = "heads"; } public Coin(int b, String faceTails) { Value = b; Face = "tails"; }
You're missing the default constructor -- one that takes no parameters at all. You'll have to give your value and face default values in this constructor. Note that Java variable names should begin with a lower-case letter, so value and face, not Value and Face. Next, your 2 parameter constructor isn't using the second parameter but rather is simply ignoring it.

以上就是Creating a class and Method for a coin flip的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏