Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

need help converting string to int  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


my errors are:

RockPaperScissors.java:30: error: method getWinner in class RockPaperScissors ca
nnot be applied to given types;
getWinner(player, computer);
^
required: int,int
found: String,int
reason: actual argument String cannot be converted to int by method invocation
conversion
RockPaperScissors.java:41: error: cannot find symbol
playerAnswer.toInt = 0;
^
symbol: variable playerAnswer
location: class RockPaperScissors
RockPaperScissors.java:43: error: cannot find symbol
playerAnswer = 1;
^
symbol: variable playerAnswer
location: class RockPaperScissors
RockPaperScissors.java:45: error: cannot find symbol
playerAnswer = 2;
^
symbol: variable playerAnswer
location: class RockPaperScissors
RockPaperScissors.java:46: error: cannot find symbol
return playerAnswer;
^
symbol: variable playerAnswer
location: class RockPaperScissors
RockPaperScissors.java:73: error: cannot find symbol
playerAnswer = playerAnswer(player);
^
symbol: variable player
location: class RockPaperScissors
6 errors



I kind of assumed it would look something like this:

public static int playerAnswer(String player)
{
Scanner Keyboard = new Scanner(System.in);
System.out.println("Choose rock, paper or scissors");
player = keyboard.nextLine(); //maybe player.toInt = keyboard.nextLine()
if (player.equalsIgnoreCase("rock"))
playerAnswer = 0; // or maybe something like player.toInt = 0; instead of having playerAnswer
else if(player.equalsIgnoreCase("paper"))
playerAnswer = 1;
else if (player.equalsIgnoreCase("scissors"))
playerAnswer = 2;
return playerAnswer;
}
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're already converting a String to an int. You're just ignoring that int and passing your original String to the method that expects an int.

A couple of other points:
  • you should only create a single Random, rather than creating a new one each time through the method. Make it a static member varaible.
  • There's no need to pass an int to your computerRandom() method. You're not using that parameter at all. Just declare a local variable instead.
  •  
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!