This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Getting 6 errors with the use of result(noob) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting 6 errors with the use of result(noob)" Watch "Getting 6 errors with the use of result(noob)" New topic
Author

Getting 6 errors with the use of result(noob)

sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
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;
}
}


Wants to change the world....
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
Actually, im getting 4 errors, just the result it keeps pointing on the command line to result.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3579
    
  14

You haven't declared result.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40


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

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
Sorry Henry, and how would i declare result?
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
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

Joined: Sep 20, 2010
Posts: 3579
    
  14

result is a variable. How do you declare other variables?
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
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

Joined: Sep 20, 2010
Posts: 3579
    
  14

Okay, let me put it another way.

What is 'result'? How can you tell?
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

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


star chaser..
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
result is the score, or the calculation of everything together but it could also be a return value?
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
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

Joined: Oct 23, 2009
Posts: 150

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

Joined: Oct 18, 2010
Posts: 34
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

Joined: Sep 20, 2010
Posts: 3579
    
  14

You're learning
sean parsons
Ranch Hand

Joined: Oct 18, 2010
Posts: 34
I hope i can continue on getting better and i hope i get helpful people like you!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting 6 errors with the use of result(noob)
 
Similar Threads
Beginner Ques. from Head Start Java book
HeadFirst SimpleDotCom compile
i am still getting compile time error in this program plz give me solution
still this code gives compile time error
Head first Java; simpledotcom problems...