COP3330 Object Oriented Programming
Background Story of this Assignment
You all should have fundamental programming knowledge coming into this course. The objective of this assignment is to get you in the mindset of programming in Object Oriented Languages such as Java. In this assignment you are going to implement a class definition of the classic Rock Paper Scissor Game using some basics of OOP that have been discussed in class.
Start Early and see the TAs and ULAs! They are here to help you! Don’t procrastinate!
Assignment Details
You are going to simulate the game Rock…Paper…Scissor game. If you haven’t played the game, you can check out the rules here https://wrpsa.com/the-official-rules-of-rock-paper-scissors/. In this assignment you will play the game against the computer. The user is considered player1 and the computer is player2. The program will simulate a game where you and the computer will try win best out of three.
The Class Constructor
The RockPaperScissorhas one overloaded constructor you will implement.
The constructor of the RockPaperScissorClass. Sets up the game by setting userwins, computerwins, game, and rand to their respective values. We also set the instance of the Scanner class to the object reference being passed from the main method. The constructor has three parameters.
1. game- representing the game number
2. seed- representing the seed for how random the game will be for the pseudo random generator
3. input – representing the instance of the Scanner Class. The reason we are only using one instance in this assignment is to allow the Python Script to use its buffer. If multiple Scanner instances are use, then the script does not work properly.
The Method Signatures
You are going to implement these user defined member methods of the Class RockPaperScissor. 5 methods are non-static and one is static.
public static void greeting()
This method displays a greeting message to the user in the terminal. The following message is displayed: "Welcome to the Rock...Paper...Scissor Game! Let me tell you the rules to this game. You and I will get to choose rock, paper, or scissor. After we made a decision, we will then reveal the choices we both made and decide a winner based on these rules. Rock beats Scissor! Paper beats Rock! Scissor beats Paper! If we both pick the same option, then it is a tie. Ready to play? Here we go! I've been told by users that I'm really good!"
public void playRound()
The playRoundmethod simulates an entire game. Each game will determine an overall winner until one has won best out of three games. The method will display the current game being played in the following format "Welcome to game GAME!" (GAME represents the current game being played). For each iteration of the round, you will display to the user the current tally of the computer and user in the round. After the displaying the information, the user will then be asked to make a choice. Hint, this is where you will call userChoice. Then the computer makes its choice. Hint, use the computerChoicemethod. Once choices are made, the user and computer will compare to see who won. Hint, use the choiceBattlemethod. Based on the result of choiceBattlethe method will then inform the user who gets a point in the round and determine if someone reached the best out of three. If someone reached 3, then the method terminates.
public int choiceBattle(int p1, int p2)
This method compares both choices of the user and will display the scenario that occurred. You will have to display all possible scenarios in the following example. Let’s say player 1 picked rock and the computer picked paper, the message "You used Rock and I used Paper!" and then "Paper Beats Rock!". After that the result of the battle is returned. Make sure to consider ALL possibilities, including ties. The method has two parameters.
1. p1- An integer representing player 1's choice 2. p2- An integer representing player 2's choice
Three possible values can be returned. Zero, if a tie occurs. One, if the user wins. Two if the computer wins.
public int userChoice()
A method that displays the choice a user can make. Option 1 is Rock Option 2 is Paper Option 3 is Scissor The method will make sure the user picks a valid option. If an invalid option is selected than the program displays the message "That is an invalid choice. Please try again." Hint. Do not create a separate instance of the Scanner class. Use the instance that was passed to the constructor.
The method returns an integer that represents the respective option.
public int computerChoice()
A method that generates a random choice the computer makes for its selection. The pseudo random generator will select a number between 1 and 3 (both inclusive). The value generated is returned.
public int getWinner()
A method that returns the winner of the game of the object based on the instance that called it. The method returns one if the user won or two if the computer won.
COP3330 Object Oriented Programming
The Class Attributes
The RockPaperScissorClass has 5 attributes that are all private!
An integer called userwinsthat will track how many times the user has won. Hint, the value should not pass 3 for each instance.
An integer called computerwinsthat will track how many times the user has won. Hint, the value should not pass 3 for each instance.
An integer called gamethat is used for displaying the current game being played. An instance of the Random class called rand.
An instance of the Scanner class called input.
The Provided Files
You were provided three files to assist you in this assignment.
1. A text file that shows a sample output of the program run in Eustis.
2. Another text file that shows a sample output formatted in a normal run. 3. A python script that will test and verify that your code output is correct. 4. A runner class that contains the main method.
Requirements
Your program must follow these requirements.
The output must match exactly (this includes case sensitivity, white space, and even new lines). Any differences in the output will cause the grader script to say the output is not correct. Test with the script provided in order to receive potential full credit. Points will be deducted! Check out the sample text file.
Your program must be able to handle input that is not correct (example, if the program asked for a number between 1-3, the program should be able to handle the situation if the user accidently typed 4). However you do not need to worry about input that will cause exceptions (such as special characters) as we will discuss that later in the semester.
Make your class attributes private. It is good practice!
Do not change the method signatures. Any changes to the method signatures will result in points being deducted.
You are welcome to create additional helper methods as long as you do not remove the required methods that have been asked in this assignment.
Do not make any changes to the Runner file that was provided for you. Any changes will result in points being deducted.
Make sure you include a comment header. Check the assignment page of how it should. It should be exactly the first line of your Java source file. See the assignment page for more info.
COP3330 Object Oriented Programming
The Rubric
Please see the assignment page in Webcourses for the Rubric of how the assignment will be evaluated.
Testing the Solution with the Python Script
Once you have completed the assignment, you will need to test it to make sure it matches Dr. Steinberg’s sample output. In Eustis, make sure to upload the Python script, your Java Solution, the Runner file, and sample text output. I would highly recommend that you have a folder with those 4 files only.
Once all of those files are uploaded into a directory in Eustis, run the command “python3 p1testscript.py”. The script will compile your Java source and execute it. You will then see the result in the form of a happy face or sad face. The happy face means your output was correct. The sad face means something was off with the output. Remember, the script is very picky with white space and new lines. Make sure you do not add any extra trailing white space or new lines. Look at the sample text output.
Tips in Being Successful
Here are some tips and tricks that will help you with this assignment and make the experience enjoyable.
Do not try to write out all the code and build it at the end to find syntax errors. For each new line of code written (my rule of thumb is 2-3 lines), build it to see if it compiles successfully. It will go a long way!
After any successful build, run the code to see what happens and what current state you are at with the program writing so you know what to do next! If the program performs what you expected, you can then move onto the next step of the code writing. If you try to write everything at once and build it successfully to find out it doesn’t work properly, you will get frustrated trying find out the logical error in your code! Remember, logical errors are the hardest to fix and identify in a program!
Start the assignment early! Do not wait last minute (the day of) to begin the assignment. Ask questions! It’s ok to ask questions. If there are any clarifications needed, please ask
TAs/ULAs and the Instructor! We are here to help!!! You can also utilize the discussion board on Webcourses to share a general question about the program as long as it doesn’t violate the academic dishonesty policy.
Copyright © 2012 - 2024 Apaxresearchers - All Rights Reserved.