3 Replies - 3360 Views - Last Post: 02 June 2010 - 06:38 AM Rate Topic: -----

#1 Guest_Taran*


Reputation:

Rock Paper Scissors Game

Posted 02 June 2010 - 05:42 AM

Could you please help me fix the errors in the program. whenever i try to run the program errors occur.

// The "Summative1" class.
import hsa.*;
public class Summative1
{
    public static void main (String[] args)
    {
        int userScore = 0;
        int compScore = 0;
        String userMove, compMove;
        int winner;

        System.out.println ("ROCK - PAPER - SCISSORS");
        System.out.println ("This game plays 10 rounds.");

        for (int rnd = 1 ; rnd <= 10 ; rnd++)
        {

            userMove = getUserMove ();
            compMove = getComputerMove ();
            System.out.println ("Computer's move: " + compMove);
            
             winner = determineRoundWinner(compMove, userMove);
             
            
            
           
            if (winner == 1) {
                System.out.println(compMove + " beats " + 
                                   userMove + 
                                   " the computer wins this round.");
                compScore++;
            }
            else if (winner == -1) {
                System.out.println(userMove + " beats " + 
                                   compMove + 
                                   " the user wins this round.");
                userScore++;
            }
            else {
                System.out.println(userMove + " ties " + 
                                   compMove + 
                                   " nobody wins this round.");
            }
            
            System.out.println("Score: User=" + userScore + 
                               " Computer=" + compScore);
            System.out.println();
        }
        
        displayGameWinner(userScore, compScore);
        
          static String getUserMove() {
        String userMove = "club";
        
         while (!userMove.equals("ROCK") &&
               !userMove.equals("PAPER") &&
               !userMove.equals("SCISSORS")) {

            System.out.print("Enter your move " +
                               "[ROCK, PAPER, SCISSORS]: ");
                               
                               
                       userMove = Console.in.readLine();
            userMove = userMove.toUpperCase();
        }

        return userMove;
    }
    
     static String getComputerMove() {
        int compMoveInt;
        String compMove;
        
               if (compMoveInt == 1) {
            compMove = "ROCK";
        }
        else if (compMoveInt == 2) {
            compMove = "PAPER";
        }
        else {
            compMove = "SCISSORS";
        }

        return compMove;
    }
   

      public static int randomInt(int lowEnd, int highEnd) {
        int theNum;
        {
        
        theNum = (int)(Math.random() * (highEnd - lowEnd + 1)) + lowEnd;

        return theNum;
        
            static int determineRoundWinner;String userMove;
                                    String compMove; {
        int winner;
        
          else if (compMove.equals("ROCK") && 
                 userMove.equals("SCISSORS")) {
            winner = 1;
            
          }
          
            else if (compMove.equals("PAPER") &&
                 userMove.equals("ROCK")) {
            winner = 1;
        }
        
           else if (compMove.equals("SCISSORS") &&
                 userMove.equals("PAPER")) {
            winner = 1;
        }
        
              else {
            winner = -1;
        }

        return winner;
    }

        static void displayGameWinner(int userScore,
                                  int compScore) {

        System.out.println("\n\nFinal Score:");
        System.out.println("       User=" + userScore + 
                           "   Computer=" + compScore);
        System.out.println();

        if (userScore > compScore) {
            System.out.println("The user wins!");
        }
        else if (compScore > userScore) {
            System.out.println("The computer wins!");
        }
        else {
            System.out.println("Its a tie, nobody wins.");
        }
    }
{


        } // main method
    } // Summative1 class


Is This A Good Question/Topic? 0

Replies To: Rock Paper Scissors Game

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Rock Paper Scissors Game

Posted 02 June 2010 - 05:48 AM

what are the errors you are receiving?
Was This Post Helpful? 0
  • +
  • -

#3 Ember  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 160
  • Joined: 24-April 10

Re: Rock Paper Scissors Game

Posted 02 June 2010 - 06:23 AM

In multiple instances I get the feeling you are a new person in Java.
userMove = Console.in.readLine();

That isn't going to do anything. I would suggest you use a Scanner Object to read in from the Console.

            static int determineRoundWinner;String userMove;
                                    String compMove; {


I don't even know what you were attempting to do here. It is supposed to be a static method which looks like:
 static int determineRoundWinner(String userMove, String compMove){
//code here
return whatever;
}


Get an IDE so you can catch errors while you are typing out the code. There are many suggestions but a few that I can think of off the top for new people is BlueJ, Eclipse or NetBeans. Though Eclipse might be a little overwhelming to look at, at first.
Was This Post Helpful? 0
  • +
  • -

#4 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





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

Re: Rock Paper Scissors Game

Posted 02 June 2010 - 06:38 AM

I wrote a Java for N00blets tutorial that you should check out if you're having problems on syntax. Also, I wrote one explaining some of the necessary components of a R,P,S game in another tutuorial. Cba to link ya, but look in the java tutorial section or look under my contributions. A lot of people said they helped, so it might help you too. ^__^

Okay, I lied
Java for N00blets

Beginning Games for N00blets: Rock, Paper, Scissors

This post has been edited by NeoTifa: 02 June 2010 - 06:44 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1