• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with my code  RSS feed

 
Vicne Kennedy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is what should I use for a RETURN statement in the inputCoord method header

Thank you for your help. This is driving me crazy

the code I am using is below.




 
Eric Sweeten
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a new class that contains those four integers, then instantiate that class and use it as the return type for that method. That way the method can create a new object of that type and put the appropriate values in those four integers, and then return that object, and then you have that object to do with as you wish.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a lot of duplication in that method. Also, it doesn't make sense to pass any of those variables as parameters to the method since they aren't used as input. Parameters are passed by value in Java so anything you do to the parameter inside the method won't affect the variable in the calling code, i.e. the main method. Just because you named the parameters the same as the variables in main does not make them connected.

What I would do is look at the code that is duplicated and see what parts are slightly different. Those are the parts that need to be parameterized.

The "conversation" in the program should be something like this:

main: hey, inputCoord, prompt the user for a value between this and that number.

inputCoord: (Goes off with this and that values, prompts user using those values, then answers ) ... User entered blah

main: (notes down value) hey, inputCoord, prompt the user for a value between this and that number.

inputCoord: (goes and does the same thing as before) ...

main: (notes down value) hey, inputCoord, ...

(you should know the drill by now)
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vicne:

Welcome to the Code Ranch! The formatting of your code is excellent. I have one minor suggestion: spacing. I like a lot of whitespace in my code but I think you have too much. Here are some basic rules that others may disagree with -- but the important thing is to have a style and stick with it.

  • No more than one blank line
  • Blank line before class and method declaration
  • Blank line above but not below single line quote
  • Blank lines around loops and if statements
  • Blank line above return statement
  • Blank line to separate a related group of statements


  • Everything else should be single spaces. Here's how I would space your code:

     
    Junilu Lacar
    Sheriff
    Posts: 11493
    180
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And it's nice that you're writing JavaDocs for your code although you might want to check out the recommended ways to write them here: http://www.oracle.com/technetwork/articles/java/index-137868.html -- see the Style Guide section.

    Specifically, avoid writing "This method"

    and prefer something like this instead:

    Also, comments like the ones below are redundant. They don't add any value and just clutter up the code. It's like taping a piece of paper on your refrigerator that says "Where I keep food until I have to throw it out. This is the refrigerator."

     
    Vicne Kennedy
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks everyone for all your help. I will take this information and see where I can get with this project. I appreciate it. As a newbie to java AND coding as well, I am just trying to feel my way as I go along and hopefully learn by doing.

    Thanks again,
    Vince Kennedy
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!