学校の課題があります。説明が非常に曖昧だと思います... 誰かがそれを読んで解釈を与えるか、教師以外の言葉で各方法を簡単に説明していただければ幸いです. 課題は次のように尋ねます... 注: 彼の説明が漠然としすぎていると感じただけです。だから、私はコードを求めていません.thanks。
The players will be children of the following (partially defined) class:
public abstract class Player implements Comparable{
public String name; // name of player
public int id; // identifier for the player
protected int wins;
protected int losses;
protected int ties;
public abstract String play(Player opponent);
// returns one of "rock", "paper", or "scissors"
public void update(String myGesture,
String opponentGesture,
Player opponent);
// this method will update the player's stats
// (wins, losses, ties) based on the gestures (inputs)
// for a recent game played against opponent (also input)
public Player(String name, int id){...}
// constructor that initializes player's name and id
You will need to fill in the code for the constructor and the update methods for the Player class. You can add other "hidden" attributes and methods as you wish (Note: if you add things to Player, be sure it is something that ALL children classes will also use). You will also need to implement three classes that extend the Player class:
public class SimplePlayer extends Player{...}
// A SimplePlayer will always play the same
// gesture (either rock, paper, or scissors)
// in every game it plays, regardless
// of who its opponent is. The gesture is
// randomly chosen when the SimplePlayer is created.
public class RandomPlayer extends Player{...}
// A RandomPlayer will always play a random
// gesture (rock, paper, or scissors) in
// every game it plays, regardless of who
// its opponent is.
public class SmartPlayer extends Player{...}
// A SmartPlayer will try to use past knowledge
// of games played against a particular
// opponent when playing them again.
You can add any hidden attributes and methods to the children classes as you wish.
編集: このクラスは Comparable を実装しているので、異なるジェスチャを比較するメソッドは play() でしょうか?