Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting 6 errors with the use of result(noob)

 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code below is what im putting into Notepad++ and when i try to run it in command prompt with java it tells me that i have 6 errors with result, do i need to make a method for result or does it already know what result is supposed to do?


public class SimpleDotCom {
int[] locationCells;
int numOfHits = 0;

public void setLocationCells(int[] locs) {
locationCells = locs;
}
public String checkYourself (String stringGuess) {
int guess = Integer.parseInt(stringGuess);
for (int cell : locationCells) {
if (guess == cell) {
result = "hit";
numOfHits++;
break;
}
}
if (numOfHits == locationCells.length) {
result = "kill";
}
System.out.println(result);
return result;
}
}
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, im getting 4 errors, just the result it keeps pointing on the command line to result.
 
Stephan van Hulst
Bartender
Pie
Posts: 5431
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't declared result.
 
Henry Wong
author
Marshal
Pie
Posts: 20907
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Next time, it would be a good idea to also show us the compiler errors too.

Henry
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Henry, and how would i declare result?
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im getting another error with String result = dot.checkYourself; im guessing it has to do with result but how would i show the complier errors because it doesn't let me copy within the command prompt. Just re-write what the compier is showing as the error?
 
Stephan van Hulst
Bartender
Pie
Posts: 5431
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
result is a variable. How do you declare other variables?
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, im only on page 90 in Head First Java, but from what i know if its a variable, usually you have to make a method something like this SimpleDotCom dot = new SimpleDotCom so then i can call the action of the variable to do something.

so if i wanted SimpleDotCom to bark i would invoke the method to do something like this.

dot.bark();
and if i want to make certain barks diffrent i would do something like this.
Dog one = new Dog
one.size = 70();
if (size < 60) {
System.out.println(" Woof Woof!");
}
Something like that, probably not though im very new to programming.
 
Stephan van Hulst
Bartender
Pie
Posts: 5431
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, let me put it another way.

What is 'result'? How can you tell?
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im getting another error with String result = dot.checkYourself; im guessing it has to do with result but how would i show the complier errors because it doesn't let me copy within the command prompt. Just re-write what the compier is showing as the error?


On the top left of the command prompt, click c:\ -> edit. You will need to mark the text and copy. This will help you on copy and pasting stuff.

Gary
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
result is the score, or the calculation of everything together but it could also be a return value?
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gary Ba wrote:
Im getting another error with String result = dot.checkYourself; im guessing it has to do with result but how would i show the complier errors because it doesn't let me copy within the command prompt. Just re-write what the compier is showing as the error?


On the top left of the command prompt, click c:\ -> edit. You will need to mark the text and copy. This will help you on copy and pasting stuff.

Gary


Thank you very much, this will help me greatly in the future.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to Stephan van Hulst, try looking up what and how to declare a variable. Google and read it.

Gary
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finally got it result is a string, so i just set it up like this String result = "miss"; as the default then i can change it to "hit" depending if the persons guess is on the cell with the ship, Thank you for helping me im very new to programming i have a long way to go!
 
Stephan van Hulst
Bartender
Pie
Posts: 5431
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're learning
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope i can continue on getting better and i hope i get helpful people like you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic