我有一个学校作业。我发现描述很模糊......如果有人会阅读它并给我他们的解释或简单地用老师以外的语言解释每种方法,将不胜感激。作业要求如下... 注意:我只是觉得他的描述太模糊了。所以我不要求代码。谢谢。
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() 会是比较不同手势的方法吗?