0

I'm taking my first Java class. I need to create a rock paper scissors game. I can't seem to figure out how to fix it. Please help! Thanks (:

I'm using NetBeans IDE 7.3 btw

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rockpaperscissors;

/**
 *
 * @author Christina
 */
import java.util.Scanner;
public class Rockpaperscissors {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int Computer = 0, Player = 0, tie = 1, compic = 0, pscore = 0, tie = 0;
        int end = 0;
        Scanner scan = new Scanner(System.in);
        while (end < 3) {
            System.out.print("scissor(0), rock (1), paper(2): ");
            pscore = scan.nextInt();
            compic = (int)(Math.random()*2);

            switch (pscore) {
                case 0 :
                    if (compic == 0)    {
                        System.out.println("The computer is scissor. You are scissor too.  It is a draw.");
                        tie++;
                                }
                    else if (compic == 1)   {
                        System.out.println("The computer is rock. You are scissor. Computer won.");
                        Computer++;
                                }
                    else    
                    {
                        System.out.println("The computer is rock. You are paper. You won.");
                        Player++;
                        end++;
                    }
                    break;
                case 1 :
                    if (compic == 0)    {
                        System.out.println("The computer is scissor. You are rock. You won.");
                        Player++;
                        end++;
                    else if (compic == 1)   {
                        System.out.println("The computer is rock. You are rock. It is a draw.");
                        tie++;
                    }
                    else     
                    {
                        System.out.println("The computer is paper. You are rock. Computer won.");
                        Computer++;
                    }
                    break;
                case 2 :
                    if (compic == 0)    {
                        System.out.println("The computer is scissor. You are paper. Computer won.");
                        Computer++;
                    }
                    else if (compic == 1)   {
                        System.out.println("The computer is rock. You are paper. You won.");
                        Player++;
                    }
                    else
                    {
                        System.out.println("The computer is paper. You are paper. It is a draw.");
                        tie++;
                    }
                    break;
                default :
                    System.out.println("Error");
                    break;
            }
        }
        System.out.println("");
        System.out.println("The player wins : " + Player);
        System.out.println("The computer wins : " + Computer);
        System.out.println("Tie : " + tie);
    }
                    }
4
Contributors
4
Replies
18
Views
3 Years
Discussion Span
Last Post by stultuske
0
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
  required: int
  found:    boolean
    at javaapplication10.JavaApplication10.main(JavaApplication10.java:20)
Java Result: 1
0

I'm not sure why you are getting that error. after I removed the duplicate variables and fixed the brackets mine seemed to work fine. make sure you close your if statement brackets and you don't declare duplicates

0

well, the main problem is: you are having an exception in the class JavaApplication10, of which you haven't shown any code.
you are somewhere in that class (line 20) treating an int as a boolean, that's your problem. saying more would be speculating.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.