6 Replies - 37532 Views - Last Post: 13 December 2010 - 12:59 PM Rate Topic: -----

#4 S06182  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 15-October 08

Re: rock, paper, scissors

Post icon  Posted 15 October 2008 - 04:44 PM

// ****************************************************************
//   Rock.java		 
//
//   Play Rock, Paper, Scissors with the user
//		  
// ****************************************************************
import java.util.Scanner;
import java.util.Random;

public class Rock
{
	public static void main(String[] args)
	{
 Scanner scan= new Scanner (system.in)
 String personPlay;	//User's play -- "R", "P", or "S"
 String computerPlay;  //Computer's play -- "R", "P", or "S"
 int computerInt;	  //Randomly generated number used to determine
					   //computer's play

System.out.print ("Enter your play: r, p, or s")
   personPlay = scan.nextLine();
   personPlay = personPlay.toUpperCase();
 
Random generator = new Random();
computerPlay = generator.nextInt (3) +1;
System.out.println ("From 1 to 3: " + computerPlay);

int computerPlay = computerInt;
int 1=R 2=P 3=S;
System.outprintln ("computerPlay:" + computerPlay);

if (personPlay.equals(computerPlay));
   System.out.println ("It's a tie!);
else if (personPlay.equals("R"))
	 if (computerPlay.equals("S"))
	 System.out.println ("Rock crushes scissors. You win!");
		else if (computerPlay.equals("P"));
		System.out.println ("Paper beats rock. Computer wins!);
else if (personPlay.equals("P")
	 if (computerPlay.equals("R")
	 System.out.println ("Paper beats rock. You win!");
		else if (computerPlay.equals("S");
		System.out.println ("Scissors cut paper. Computer wins!");
else if (personPlay.equals("S")
	 if (computerPlay.equals("R")
	 System.out.println ("Rock crushes scissors. Computer wins!");
		 else if (computerPlay.equals("P");
		 System.out.println ("Scissors cut paper. You win!");



	}
}


Mod edit - Please :code:
~BetaWar
Was This Post Helpful? 1

#5 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,135
  • Joined: 07-September 06

Re: rock, paper, scissors

Posted 15 October 2008 - 04:50 PM

What problems are you facing? Are there any errors?
Was This Post Helpful? 0
  • +
  • -

#6 S06182  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 15-October 08

Re: rock, paper, scissors

Posted 15 October 2008 - 07:55 PM

View PostBetaWar, on 15 Oct, 2008 - 04:50 PM, said:

What problems are you facing? Are there any errors?


well, i dont know whats the problem... but it doesnt work. and im not sure if some of statements are even valid... can you tell if there are any errors? and if there are, what should i do?
Was This Post Helpful? 0

#18 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2651
  • View blog
  • Posts: 15,674
  • Joined: 24-September 08

Re: rock, paper, scissors

Posted 16 October 2008 - 05:51 AM

i made a rock paper scissors program myself. i havent worked on it in a while, and its very primitive and unclean. ill post it for you and you can compare it to yours if you want. i dont care what you do, its basically a skeleton, but you should thank me for it (and by thank i mean click the "this post was helpful" button so i look like i actually contributed to the forums) lol :P

package rockpaperscissors;

/**
 * 
 * @author Erica
 * @date 9-25-08
 * 
 * A simple program to utilize the Random class
 */

//imports
import javax.swing.JOptionPane;
import java.util.Random;

public class Main {

	public static void main(String[] args) {
	   
		String input;					   //stores user input from JOP
		int uchoice;						//parse of input; users choice
		int compchoice;					 //random choice by computer

		//prompts for user input and then parses it to uchoice
		input = JOptionPane.showInputDialog("What'll it be? Rock, paper, or scissors?\n" +
				"1 for rock, 2 for paper, and 3 for scissors: ");
		uchoice = Integer.parseInt(input);
		
		//generates random number and sets a limit
		Random randomnum = new Random ();
		
		compchoice = randomnum.nextInt(3);
		
		//determines whether the user or computer wins
		if (uchoice == 1 && compchoice == 0)
				JOptionPane.showMessageDialog(null, "Tie!");
		
		else if (uchoice == 1 && compchoice == 1)
				JOptionPane.showMessageDialog(null, "Paper beats rock. You lose!");
		
		else if (uchoice == 1 && compchoice == 2)
				JOptionPane.showMessageDialog(null, "Rock beats scissors. You win!");
		
		else if (uchoice == 2 && compchoice == 0)
				JOptionPane.showMessageDialog(null, "Paper beats rock. You win!");
		
		else if (uchoice == 2 && compchoice == 1)
				JOptionPane.showMessageDialog(null, "Tie!");
		
		else if (uchoice == 2 && compchoice == 2)
				JOptionPane.showMessageDialog(null, "Scissors beats paper. You lose!");
		
		else if (uchoice == 3 && compchoice == 0)
				JOptionPane.showMessageDialog(null, "Rock beats Scissors. You lose!");
		
		else if (uchoice == 3 && compchoice == 1)
				JOptionPane.showMessageDialog(null, "Scissors beats paper. You win!");
		
		else if (uchoice == 3 && compchoice == 2)
				JOptionPane.showMessageDialog(null, "Tie!");
	   
		
	}
	

}


This post has been edited by NeoTifa: 16 October 2008 - 05:52 AM

Was This Post Helpful? 1

#19 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: rock, paper, scissors

Posted 16 October 2008 - 06:38 AM

View PostS06182, on 15 Oct, 2008 - 04:44 PM, said:

// ****************************************************************
//   Rock.java		 
//
//   Play Rock, Paper, Scissors with the user
//		  
// ****************************************************************
import java.util.Scanner;
import java.util.Random;

public class Rock
{
	public static void main(String[] args)
	{
 Scanner scan= new Scanner (system.in)
 String personPlay;	//User's play -- "R", "P", or "S"
 String computerPlay;  //Computer's play -- "R", "P", or "S"
 int computerInt;	  //Randomly generated number used to determine
					   //computer's play

System.out.print ("Enter your play: r, p, or s")
   personPlay = scan.nextLine();
   personPlay = personPlay.toUpperCase();
 
Random generator = new Random();
computerPlay = generator.nextInt (3) +1;
System.out.println ("From 1 to 3: " + computerPlay);

int computerPlay = computerInt;
int 1=R 2=P 3=S;
System.outprintln ("computerPlay:" + computerPlay);

if (personPlay.equals(computerPlay));
   System.out.println ("It's a tie!);
else if (personPlay.equals("R"))
	 if (computerPlay.equals("S"))
	 System.out.println ("Rock crushes scissors. You win!");
		else if (computerPlay.equals("P"));
		System.out.println ("Paper beats rock. Computer wins!);
else if (personPlay.equals("P")
	 if (computerPlay.equals("R")
	 System.out.println ("Paper beats rock. You win!");
		else if (computerPlay.equals("S");
		System.out.println ("Scissors cut paper. Computer wins!");
else if (personPlay.equals("S")
	 if (computerPlay.equals("R")
	 System.out.println ("Rock crushes scissors. Computer wins!");
		 else if (computerPlay.equals("P");
		 System.out.println ("Scissors cut paper. You win!");



	}
}


Mod edit - Please :code:
~BetaWar


I attempted to fix your code however there is so much going on i got lost lol

rember to use { and } to make your if and if else statements clear. I really had no idea what you were doing.
Was This Post Helpful? 0
  • +
  • -

#20 Guest_Boolean*


Reputation:

Re: rock, paper, scissors

Posted 13 December 2010 - 11:50 AM

I just finsihed a really basic one
/******************************************************************************
*
* this program Plays a game of Rock paper scissors to 5 points 
*
*The CPU Choose either rock paper scissors Through java.util.Random;
*
*This program is really basic and DOES NOT use GUI
*******************************************************************************/
import hsa.Stdin;
import java.util.Random;
public class RockPaperScissors
{
    public static void main (String[] args)
    {
        System.out.println ("A Game of Rock, Paper, Scissors to 5 points");
        System.out.println();
    
        //Player Name not needed overall
        String player, cpu;
        System.out.println ("enter your name: ");
        player = Stdin.readString ();

        int playerScore = 0;
        int cpuScore = 0;



       

        //determines winner
        while ((playerScore != 5) && (cpuScore != 5))
        {
            //sets computer answer
            Random randomNum = new Random ();
            int cpuChoice = randomNum.nextInt (3) + 1;
            //System.out.print (cpuChoice);
            
            System.out.println (player + " choose 1 for rock, 2 for paper, or 3 for scissors: ");
            int playerChoice = Stdin.readInt ();
            while ((playerChoice != 1) && (playerChoice != 2) && (playerChoice != 3))
            {

                System.out.println (" invalid choice you muct pick between 1 2 or 3");
                System.out.println (player + " choose 1 for rock, 2 for paper, or 3 for scissors: ");
                playerChoice = Stdin.readInt ();

            }

            if (playerChoice == cpuChoice)
            {
                System.out.println ("its a tie no points awarded");
                System.out.println ();
            }

            if ((playerChoice == 1) && (cpuChoice == 2))
            {
                System.out.println (player + " chose rock, CPU chose paper\n CPU's point");
                cpuScore++;
                System.out.println ();
            }
            else if ((playerChoice == 2) && (cpuChoice == 1))
            {
                System.out.println (player + " chose paper, CPU chose rock\n" + player + " gets the point");
                playerScore++;
                System.out.println ();
            }
            else if ((playerChoice == 1) && (cpuChoice == 3))
            {
                System.out.println (player + " chose rock, CPU chose scissors\n" + player + " gets the point");
                playerScore++;
                System.out.println ();
            }
            else if ((playerChoice == 3) && (cpuChoice == 1))
            {
                System.out.println (player + " chose scissors, CPU chose rock\nCPU gets the point");
                System.out.println ();
                cpuScore++;
                //break;
            }
            else if ((playerChoice == 3) && (cpuChoice == 2))
            {
                System.out.println (player + " chose scissors, CPU chose paper\n" + player + " gets the point");
                playerScore++;
                System.out.println ();
            }
            else if ((playerChoice == 2) && (cpuChoice == 3))
            {
                System.out.println (player + " chose paper, CPU chose scissors\nCPU gets the point");
                cpuScore++;
                System.out.println ();
            }
            if (playerScore == 4)
            {
                System.out.println (player + " only needs one point to win");
            }
            if (cpuScore == 4)
            {
            System.out.println ("CPU only needs one point to win");
            }
             
        }
            if (playerScore == 5)
            {
            System.out.println ("Game over " + player +" has won");
            System.out.println ("FINAL SCORE");
            System.out.println (player +" had " + playerScore + " points");
            System.out.println ("CPU had " + cpuScore + " points");
            
            }
            if (cpuScore == 5)
            {
            System.out.println ("Game over CPU has won");
            System.out.println ("FINAL SCORE");
            System.out.println ("CPU had " + cpuScore + " points");
            System.out.println (player +" had " + playerScore + " points");
            
            
            }
            

    } // main method
}
// RockPaperScissors class


This post has been edited by macosxnerd101: 13 December 2010 - 11:53 AM
Reason for edit:: Please use code tags

Was This Post Helpful? 0

#21 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2871
  • View blog
  • Posts: 11,026
  • Joined: 15-July 08

Re: rock, paper, scissors

Posted 13 December 2010 - 12:59 PM

Congatulations! However, this topic is 2 years old and I don't think the OP will be coming back anytime soon.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1