Skip to content
Sign upLog in
← Back to Community

Why is my object playerDecision not localized? does anyone have any suggestions on how to fix this?

Profile icon
JoshuaTarman

/*

  • Programmer: yourName
  • Date: mm-dd-2020
  • Project 3.06 - ROCK PAPER SCISSORS
  • Purpose: Apply Logical Operators
    */

// import the Scanner utility
import java.util.Random;
import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
clear();

System.out.println("Project 3.06"); System.out.println("ROCK PAPER SCISSORS"); System.out.println("Apply Logical Operators"); // instantiate a Scanner object for user input Scanner sc = new Scanner(System.in); System.out.println("\nROCK PAPER SCISSORS"); System.out.print("\nYou will play the computer for one round of "); System.out.println("ROCK PAPER SCISSORS."); System.out.println("You will choose first."); System.out.println("Then, the computer will randomly select its choice."); // Players turn System.out.print("\nPress enter to begin the game ... ");

int rockP = 0;
int paperP = 1;
int scissorsP = 2;
int playerDecision;
String wait = sc.nextLine(); // wait is a temp variable to pause the game
System.out.print("\nRock, Paper, or Scissors: ");
String userInput = sc.nextLine();
if (userInput.equalsIgnoreCase("rock"))
{
playerDecision = rockP;
System.out.print("\nYou chose rock");

} else if(userInput.equalsIgnoreCase("paper")) { playerDecision = paperP; System.out.print("\nYou chose paper"); } else if(userInput.equalsIgnoreCase("scissors")) { playerDecision = scissorsP; System.out.print("\nYou chose scissors"); } else { System.out.print("\nINVALID INPUT"); } //computers turn

System.out.print("\n\nPress enter to continue the game ...");
wait = sc.nextLine();
System.out.print("\n\nCOMPUTER'S INPUT");
Random rand = new Random(); //instance of random class
int upperbound = 3;
//generate random values from 0-24
int computerInput = rand.nextInt(upperbound);

int computerDecision;

int rockC = 0;
int paperC = 1;
int scissorsC = 2;
if (computerInput == 0)
{
computerDecision = rockC;
System.out.print("\nThe Computer chose rock");

} else if(computerInput == 1) { computerDecision = paperC; System.out.print("\nThe Computer chose paper"); } else if(computerInput == 2) { computerDecision = scissorsC; System.out.print("\nThe Computer chose scissors"); // Game computerDecision if(playerDecision == computerDecision) { System.out.print(" "); } else if(playerDecision == 0 || computerDecision == 1 ) { System.out.print("\nA foolish man once tried to beat a piece of paper up with a rock, but he lost when the paper wrapped around his rock...In other words you lost."); } else if(playerDecision == 0 || computerDecision == 2 ) { System.out.print("\nYou win, but why just why would someone try to cut a rock with scissors!? "); } else if(playerDecision == 1 || computerDecision == 0 ) { System.out.print("\n A wise man once stopped a crazed man holding a rock by wrapping paper around the rock... I guess you won."); } else if(playerDecision == 1 || computerDecision == 2 ) { System.out.print("\nYou lost, but I mean you had to of seen that coming why wouldnt scissors cut paper?"); } else if(playerDecision == 2 || computerDecision == 0 ) { System.out.print("\nWhy would you try to cut a rock with scissors, what did you think was going to happen?!... \n\nOh you totally lost."); } else if(playerDecision == 2 || computerDecision == 1 ) { System.out.print("\nThere you go! Scissors cut paper, finally you won with something that actually makes sense"); }

}

System.out.println(""); // for spacing in the repl.it console } // a method to clear the replit console public static void clear() { System.out.print("\033[H\033[2J"); System.out.flush(); }

}

Voters
Profile icon
JoshuaTarman
Comments
hotnewtop
Profile icon
bottlesandcaps

some ofyour fnctions arent being called right i think