1.11M Members

need help with this driving me crazy

 
0
 
// The "FriedmanRPSgame" class.
import java.awt.*;
import hsa.Console;

public class FriedmanRPSgame
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
 c = new Console ();

// VARIABLES
 int  rock;
 int  paper;
 int  scissors;

// INPUT
  c.println (" Choose 1 for rock, 2 for paper, 3 for scissors");
  int choice =c.readInt();
  int computer = Math.floor((Math.random()*3)+1);


 if (Computer == 1 && choice == 2 ||Computer == 2 && choice == 3 || computer == 3 && choice == 1)
 {
     c.println ("You win!!");
 }

 else if (choice == 1 && computer == 2 || choice == 2 && computer == 3 || choice == 3 && computer == 1)

     {
  c.println ("You Lose!!");
     }
 else if (computer == choice)
 {
     c.println ("Tryagain!");
 }
 // Place your program here.  'c' is the output console
    } // main method
} // FriedmanRPSgame class
 
0
 

And what is your question?

 
0
 

first of all you have capitalization problems in your code (Computer). Then you also need to put brackets around each of the cases when you are checking them.

 
0
 

Compiler output:

FriedmanRPSgame.java:3: error: package hsa does not exist
import hsa.Console;
          ^
FriedmanRPSgame.java:7: error: cannot find symbol
    static Console c;           // The output console
           ^
  symbol:   class Console
  location: class FriedmanRPSgame
FriedmanRPSgame.java:11: error: cannot find symbol
 c = new Console ();
         ^
  symbol:   class Console
  location: class FriedmanRPSgame
FriedmanRPSgame.java:21: error: possible loss of precision
  int computer = Math.floor((Math.random()*3)+1);
                           ^
  required: int
  found:    double
FriedmanRPSgame.java:24: error: cannot find symbol
 if (Computer == 1 && choice == 2 ||Computer == 2 && choice == 3 || computer ==
3 && choice == 1)
     ^
  symbol:   variable Computer
  location: class FriedmanRPSgame
FriedmanRPSgame.java:24: error: cannot find symbol
 if (Computer == 1 && choice == 2 ||Computer == 2 && choice == 3 || computer ==
3 && choice == 1)
                                    ^
  symbol:   variable Computer
  location: class FriedmanRPSgame
6 errors

In addition to what has been said:

  • Math.floor() returns a double, and you are assigning it to a primitive of type int, what you want is a cast.
  • hsa.Console? From the context I assume that this class is used for outputting things. I'm just wondering... What is the great benefit of using this class as opposed to using something that comes with the Java libraries? I suggest you to take a look here. You can access an instance of PrintStream using the static out reference variable of the System class. E.g. System.out.println("You win!!!").
  • Next time it would be great if you could point out the issue that you are encountering, How To Ask Questions The Smart Way by ESR is a wonderful read.
 
1
 

hsa.Console? From the context I assume that this class is used for outputting things. I'm just wondering... What is the great benefit of using this class as opposed to using something that comes with the Java libraries? I suggest you to take a look here. You can access an instance of PrintStream using the static out reference variable of the System class. E.g. System.out.println("You win!!!").

I recongize the hsa console. It is a built in console in the Ready to Program IDE. It is essentially a TextArea that works like the command prompt and "simplifies" reading user input that is entered into the console.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: