Java游戏代写 | Java Game PA



The goal of this assignment is to re-familiarize yourself with Java and inheritance. Additionally, you will gain familiarity with the course turn-in procedures, learn the basics of unit testing with JUnit, and implement a modest-sized programming problem using Arrays.

Getting Started

We strongly recommend that you work on EdStem, but if you choose to work on your own machine, make sure your code runs correctly on EdStem, as that is where we will be testing it.


On this assignment, we will give you feedback on style but not deduct points for problems with style. For future assignments, we will be grading the following for style on all files you submit:

  • File header
  • Class header
  • Method header(s)
  • Inline comments
  • Proper indentation
  • Descriptive variable names
  • No magic numbers (Exception: Magic numbers can be used for testing.)
  • Reasonably short methods (if you have implemented each method according to specification in this write-up, you’re fine). This is not enforced as strictly.
  • Lines shorter than 80 characters
  • Javadoc conventions (@param, @return tags, /** comments */, etc.)

A full style guide can be found here. If you need any clarifications, feel free to ask on EdStem.

Part 1: Implementation

Inheritance hierarchy

In this assignment, you will create a computer game to play standard Rock-Paper-Scissors and modified Rock-Paper-Scissors with a user. We have split this into an interface, an abstract class, and two concrete classes so we can practice inheritance.

The top-level is RPSInterface, which specifies the instance methods. RPSAbstract implements RPSInterface and has concrete implementations of two instance methods. RPS and RPSModified extend RPSAbstract and have their own implementations of one instance method and the main method.

We have provided starter code following this hierarchy. Do not change the interface or the inheritance hierarchy.

Problem 1a

In this problem you will implement standard Rock-Paper-Scissors. If you are unfamiliar with this game, you can read about it on Wikipedia here.

When the user starts your game, it should play the game of Rock Paper Scissors with the user until the user types ‘q’. Here is an example run. User input is after the “(Type the move or q to quit)”

Additional output examples can be viewed at the end of the writeup under “Example Output for Problem 1a“.

Your task is to implement the following methods in the following files:

Instance Variables

  • String[] possibleMoves: an array that stores all possible moves. Each element in the array beats the next element in the array, and the end wraps around to the beginning. All other pairings lead to a tie. This means each move beats one move and loses to one move. For example, { “scissors”, “paper”, “rock” } indicates scissors beats paper, paper beats rock, and rock beats scissors.


  • public String genCPUMove(): generates a random String for the CPU’s move. This should randomly return one move from the possibleMoves
    • Generate a random number using the Random object rand we have already defined for you.
    • Use that random number as the index of possibleMoves, and return the move at that index.
    • Each element in possibleMoves should have an equal chance of being chosen.
  • public int play(String playerMove, String cpuMove): determines and returns game outcome based off the possibleMoves. Each move beats the next move in the possibleMoves array, and all other pairings result in a tie. Return -1 for invalid move, 0 for tie, 1 for player win, and 2 for CPU win.
    • Assume there are at least 3 moves in possibleMoves.
    • There can be more than 3 moves in possibleMoves, so do not hardcode the logic.
    • An invalid move is a move that is not in the possibleMoves
    • If the move is invalid, use INVALID_INPUT to print out “That is not a valid move. Please try again.”.
    • Print out the CPU’s move using CPU_MOVE. For example if it chose paper, print “I chose paper. “. Do not add a new line, so that the result can be printed on the same line.
    • If the player won, use PLAYER_WIN to print out “You win.”. If the CPU won, use CPU_WIN to print out “I win.”. If there was a tie, use TIE print out “It’s a tie.”.
    • We have provided the necessary Strings for when you need to print. Use these for consistency for when we test your output.

Instance Variables

  • numPlayerWins: the number of times the player won
  • numCPUWins: the number of times the CPU won
  • numTies: the number of times the player and CPU tied
  • numGames: the total number of games played
  • playerMoves: a String array storing the player’s move history
  • cpuMoves: a String array storing the CPU’s move history


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail:  微信:itcsdx