Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 作业概述说明_Java_Oop - Fatal编程技术网

Java 作业概述说明

Java 作业概述说明,java,oop,Java,Oop,我有一个学校作业。我发现描述很模糊。。。如果有人能读一遍,给我他们的解释,或者简单地用老师以外的语言解释每种方法,我将不胜感激。作业要求如下。。。注:我只是觉得他的描述太模糊了。所以不,我不是要代码。谢谢 The players will be children of the following (partially defined) class: public abstract class Player implements Comparable{ public String name

我有一个学校作业。我发现描述很模糊。。。如果有人能读一遍,给我他们的解释,或者简单地用老师以外的语言解释每种方法,我将不胜感激。作业要求如下。。。注:我只是觉得他的描述太模糊了。所以不,我不是要代码。谢谢

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()会是比较不同手势的方法吗?

我用我自己的话重新编写了他要求的内容,我们无能为力

  • play()返回玩家选择的任何手势

  • update()确定谁赢了,并将+1添加到他们的赢、输或赢 根据手势打领带

  • Player()初始化播放器名称和id

  • SimplePlayer()初始化要使用的手势。这将继续下去 不变的

  • RandomPLayer()将每个游戏中的手势初始化为随机 它播放

  • SmartPlayer()根据手势选择一个手势 对方玩家通常使用


我将尝试在这里重新阐述显而易见的(?)。老师为您提供了一个抽象类
Player
,并要求您实现
SimplePlayer
RandomPlayer
类。您应该实现相应的构造函数,还应该实现抽象和更新方法

SimplePlayer
类需要用随机手势引导。您需要随机选择一种手势,可以是石头、剪刀或布,并将其作为
play
方法的输出返回。这意味着无论对手的策略是什么,SimplePlayer都需要保持不变

相反,
RandomPlayer
每次需要返回一个随机策略;具体来说,
play
方法需要返回一个随机值

update(…)
方法可能是一个有趣的方法。根据当前玩家和对手的策略,你需要更新结果。如果您不熟悉这些规则,请参阅。简单地说,你可能需要一堆
if..else
块来比较当前玩家和对手玩家的策略


希望这对您有所帮助,祝您在实现过程中好运。

该网站主要用于编写代码。这听起来像是你应该问老师的问题。除非你有具体问题,否则我们将无法帮助你。这不是一个Java到纯英语翻译的地方。例如,您知道什么是
抽象类吗?请查看更新并告诉我您的想法!