私はこれをするように頼まれました:
第 5 章で示した Coin クラスから派生した MonetaryCoin というクラスを設計して実装します。その値を表す通貨コインに値を格納し、通貨値のゲッター メソッドとセッター メソッドを追加します。
Coin クラスは次のとおりです。
public class Coin
{
public final int HEADS = 0;
public 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.
// -----------------------------------------------
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;
}
}
私はこれを思いつきました:
public class MonetaryCoinHW extends Coin
{
public MonetaryCoinHW(int face)
{
setFace(face);
}
public int getFace()
{
if (isHeads()) {
return HEADS;
}
return TAILS;
}
public void setFace( int newFace )
{
while (newFace != getFace()) {
flip();
}
}
しかし、構文エラーが発生し続けます...「スーパー」を正しく使用していませんか? 私は完全に混乱しています。私の間違いは何ですか?