• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting 6 errors with the use of result(noob)

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, im getting 4 errors, just the result it keeps pointing on the command line to result.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't declared result.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, let me put it another way.

What is 'result'? How can you tell?
 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're learning
 
sean parsons
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope i can continue on getting better and i hope i get helpful people like you!
 
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic