Rock Paper Scissors Game Java

Posted By admin On 05.12.20

Steps of the Rock Paper Scissors Java Program We will create a class Player.java that represents the user who is going to play the game with the computer. The class Computer.java represents the Computer that is playing with the user. Driver.java is a helper class containing the Rock Paper Scissor constant variables and the business logic code. The “Rock, Paper and Scissors” is a classic game that can be used as an excuse to grasp the basics of a programming language (C in this tutorial). To execute multiple rounds of the game, a swift flow of control is required.

Active4 years, 6 months ago

I'm new to programming and I'm trying to write a very simple Rock, Paper, Scissors game in Java. It will compile and run fine, but I am looking to say something like 'Invalid move. Try again.' or something along those lines for when the user (personPlay) does not enter a correct character (r, p, or s). What would be the best way to do so? For example, if you enter a 'q', it should print 'Invalid move.' Thank you so much in advance!

}

skaffman
353k91 gold badges748 silver badges734 bronze badges
user2850883

closed as too broad by davidism, skaffman, Radiodef, WilQu, GenericJonMar 30 '15 at 12:37

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

5 Answers

I would recommend making Rock, Paper and Scissors objects. The objects would have the logic of both translating to/from Strings and also 'knowing' what beats what. The Java enum is perfect for this.

My version of Windows is XP Pro. I want to do a Winows repair but can't find the original disc. A few days ago my computer refused to boot after a power outage and I got blue screened(Non mountable disc error). Windows xp restore disk download.

The parseType method can return null if the String is not a valid type. And you code can check if the value is null and if so, print 'invalid try again' and loop back to re-read the Scanner.

27 rows  The Best Silkroad Online Private Server, download, database, fansite, guild, guide. Rank Server Votes; Origin Online - NO BOTS - The Original Experience. Origin Online is an unique server with all features of the Original Silkroad game, the game we all know and love. SPONSORED: 1. Silkroad Online - Free servers, Private servers, Guides, Guilds, Time till toplist reset: 5 days, 17 hours, 40 minutes from now. Details Legion Silkroad private server 140 CAP 140lv Skills New STYRIA event 15d items 100x Exp 100x SP 10x Gold Vote for silks Coin System Special Upgrade system Active Job Custom items and more Join US. The first quest based silkroad-r private server ever created. Let's play sro-r, the game you've felled in love with, before bots existed. Download SROMANIA now! 21 rows  Silkroad-Servers.com List the best Silkroad Online Private Servers in one list for 2017. Download silkroad private server.

Furthermore, your type enum can determine what beats what by having each Type object know:

Rock Paper Scissors Lizard Spock Game Java Code

each type will implement this method differently to see what beats what:

Then in your code

dkatzeldkatzel
26.6k2 gold badges49 silver badges58 bronze badges
Serge SeredenkoSerge Seredenko

Rock Paper Scissors Game Online

3,1617 gold badges17 silver badges35 bronze badges

Before we try to solve the invalid character problem, the lack of curly braces around the if and else if statements is wreaking havoc on your program's logic. Change it to this:

Much clearer! It's now actually a piece of cake to catch the bad characters. You need to move the else statement to somewhere that will catch the errors before you attempt to process anything else. So change everything to:

Rock Paper Scissors Java Code

musical_codermusical_coder
3,8573 gold badges11 silver badges17 bronze badges

Why not check for what the user entered and then ask the user to enter correct input again?

eg:

for the other modifications, please check my total code at pastebin

Simple Javascript Rock Paper Scissors Game

Srihari

Rock Paper Scissors Game Variations

Srihari
6631 gold badge5 silver badges20 bronze badges
Pang
7,25916 gold badges68 silver badges108 bronze badges
Peter KimPeter Kim