Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:57:01+00:00 2026-06-04T03:57:01+00:00

I’m a beginner to java programming, and was trying to make a Rock Paper

  • 0

I’m a beginner to java programming, and was trying to make a Rock Paper Scissors game.
I apologize for the lack of comments.

This is my main program, it calls on the other two objects.

 import java.util.*;

  public class RPSMain extends RPSPlayer{
   RPSPlayer player = new RPSPlayer();
   RPSGame gameObject = new RPSGame ();
   public void main () {


     Random generator = new Random ();
     Scanner sc = new Scanner(System.in);
     System.out.print ("Number of Rounds: ");
     int rounds = sc.nextInt();


    //Call and process all of the methods found in RPSPlayer and RPSGame
     for (int i = 0; i < rounds; i++){
        player.makeThrow();
        gameObject.makeThrow();
        gameObject.announceWinner (compThrow, getPThrow);
     }
    //Final Output
     System.out.print (gameObject.bigWinner(winner, rounds));
  }
//accessor to return round to RPSGame
   public static int getRound (int round){
     this.round = round;
     return round;
  }
}

My first object is where the player inputs the number of throws that they would like, and it is processed there.

  import java.util.*;

  public class RPSPlayer {

  public static void main (String args[]) {
     Random generator = new Random ();
     Scanner sc = new Scanner(System.in);
  }
//This method gets the throw, and loops if throw is not within 1 and 3
  public static int makeThrow (){
     Scanner sc = new Scanner (System.in);
     int playerThrow;
     do{
        System.out.print ("Enter your throw (1=Rock, 2=Paper, 3=Scissors)");
        playerThrow = sc.nextInt();
     } while (playerThrow > 3 && playerThrow < 1);
     return playerThrow;
  }

    //Accessor method
  public static int getThrow (int playerThrow){
    this.playerThrow = playerThrow;
     return playerThrow;
  }


 }

The last object is where all of the calculations happen.
There is a lot of variables that don’t compile properly, and I can’t quite figure out why…

  import java.util.*;

 public class RPSGame extends RPSPlayer{
  RPSPlayer player = new RPSPlayer();
  RPSGame game = new RPSGame ();
  RPSMain mainRPS = new mainRPS();
   public static void main (String args[]) {

     Random generator = new Random ();
     Scanner sc = new Scanner(System.in);
     int rounds = mainRPS.getRound(rounds);
   }
   //Random Throw Generator
   public static int makeCompThrow (){
     int Max = 3;
     int Min = 1;

     int compThrow =   Min + (int)(Math.random() * ((Max - Min) + 1));
     return compThrow;
  }

   //  Get the throw from the player in RPSPlayer
       public static int getPlayerThrow (){
     RPSPlayer player = new RPSPlayer();
     int getPThrow = player.makeThrow();
     return getPThrow;
  }

 //Does all of the calculatoins and ouputs who threw what.
   public static int announceWinner (int compThrow, int getPThrow) {
     int winner = 0;

     if (getPThrow == 1){
        System.out.println ("Player throws ROCK.");
     }
     else if (getPThrow == 2){
        System.out.println ("Player throws PAPER.");
     }
     else if (getPThrow == 3){
        System.out.println ("Player throws SCISSORS.");
     }


     if (compThrow == 1){
        System.out.println ("Computer throws ROCK.");
     }
     else if (compThrow == 2){
        System.out.println ("Computer throws PAPER.");
     }
     else if (compThrow == 3){
        System.out.println ("Computer throws SCISSORS.");
     }

     if (getPThrow == compThrow){
        winner = 3;
     }
     else if (getPThrow == 1 && compThrow == 3){
        winner = 1;
     }
     else if (getPThrow == 1 && compThrow == 2){
        winner = 2;
     }
     else if (getPThrow == 2 && compThrow == 1){
        winner = 1;
     }
     else if (getPThrow == 2 && compThrow == 3){
        winner = 2;
     }
     else if (getPThrow == 3 && compThrow == 1){
        winner = 2;
     }
     else if (getPThrow == 3 && compThrow == 2){
        winner = 1;
     }  

     return winner;
   }

//Final Output with imported values of 'rounds' and 'winner'
   public int bigWinner (int winner, int rounds){
     int tie = 0;
     int playerWins = 0;
     int compWins = 0;

     if (winner == 1){
        playerWins = playerWins + 1;
     }

     else if (winner == 0){
        tie = tie + 1;
     }

     else if (winner == 3){
        compWins = compWins + 1;
     }
     System.out.println ("You win " +playerWins+ ". Computer wins " +(compWins)+ ".");
     if (playerWins > compWins){
        System.out.print ("You win!"); 
     }
     if (playerWins < compWins){
        System.out.print ("Computer wins!"); 
     }

     if (playerWins == compWins){
        System.out.print ("It's a tie!"); 
     }
     return tie;
  }


 }

When compiled again, 2 new errors appear after adding in WATTO Studios’ suggestions, these are the compiler errors:

RPSMain.java:23: cannot find symbol
symbol  : variable winner
location: class RPSMain
     RPSGame.bigWinner(winner, rounds);
                       ^
RPSMain.java:23: non-static method bigWinner(int,int) cannot be referenced 
from a static context
     RPSGame.bigWinner(winner, rounds);

Why can’t it find the variable ‘winner’ if I’m referencing from RPSGame, and why is it still searching RPSMain for the variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:57:02+00:00Added an answer on June 4, 2026 at 3:57 am

    For these errors, in your RPSMain class, you’re trying to access variables from your other classes. Your code here…

     for (int i = 0; i < rounds; i++){
        player.makeThrow();
        gameObject.makeThrow();
        gameObject.announceWinner (compThrow, getPThrow);
     }
    

    Should actually be this…

     for (int i = 0; i < rounds; i++){
        int playerThrow = player.makeThrow();
        int compThrow = gameObject.makeCompThrow();
        gameObject.announceWinner (compThrow, playerThrow );
     }
    

    Note that when we call a method like makeThrow(), we capture the variable and call it playerThrow. Now we can use this variable in the announceWinner() method. The same for the compThrow variable.

    You are doing the same thing in your RPSGame.bigWinner(winner, rounds); line – its complaining that winner doesn’t exist. This is true – winner is not a variable in RPSMain, its only a variable in RPSGame – you can’t share the variables between different classes like this.

    Your gameObject.announceWinner() method returns an int that represents the actual winner. If you want to use this returned value, you need to capture it into a variable. Currently you have code like this in RPGMain…

    for (int i = 0; i < rounds; i++){
       int playerThrow = player.makeThrow();
       int compThrow = gameObject.makeCompThrow();
       gameObject.announceWinner (compThrow, playerThrow );
    }
    System.out.print (gameObject.bigWinner(winner, rounds));
    

    If you want to keep the int returned from the announceWinner() method, you have to capture it by making the following adjustment…

    for (int i = 0; i < rounds; i++){
       int playerThrow = player.makeThrow();
       int compThrow = gameObject.makeCompThrow();
       int winner = gameObject.announceWinner (compThrow, playerThrow );
       System.out.print (gameObject.bigWinner(winner, rounds));
    }
    

    This now says that the value returned from gameObject.announceWinner() will be stored in a local variable called winner in the RPGMain class. Now When it tries to use the winner variable in the gameObject.bigWinner() method of the next line, it knows about the value.

    To fix your non-static method bigWinner(int,int) cannot be referenced from a static context error, you need to change the following line…

    public int bigWinner (int winner, int rounds){
    

    to have the word static in it, like this…

    public static int bigWinner (int winner, int rounds){
    

    Or, better yet, remove the word static from everywhere in your code. If you’re new to Java, trying to use static variables and methods will just make things more complicated then they really need to be, and I can’t see any reason why you’d need them to be static in your program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.