1,105,406 Community Members

need help with this driving me crazy

brodeur
Newbie Poster
1 post since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
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
Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
0
 

And what is your question?

Member Avatar
sirlink99
Master Poster
766 posts since Oct 2010
Reputation Points: 44 [?]
Q&As Helped to Solve: 25 [?]
Skill Endorsements: 3 [?]
 
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.

Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
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.
Member Avatar
sirlink99
Master Poster
766 posts since Oct 2010
Reputation Points: 44 [?]
Q&As Helped to Solve: 25 [?]
Skill Endorsements: 3 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: