Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can some one let me know if this code makes sense?

 
Alain Fallada
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program works but this is a section i want to have checked. i have dificulties with private, static, public instance variables.

 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

In future, while posting code, please UseCodeTags I have added them this time for you. As you can see the tags make the code much more easier to read and understand.
Also, you seem to have missed out on the braces (hopefully while posting) Please edit your post and correct them.

Posting a bunch of code and saying "
i have dificulties with private, static, public instance variables.
" does not really help us help you. Do you have any specific questions?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What difficulties exactly do you have with private, public and static member variables?

Here are some links to the relevant parts of Oracle's Java tutorials:

Controlling Access to Members of a Class
Understanding Instance and Class Members
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a little rule of thumb about static members.

If you have a good explanation why you want it static, then is should be static.
If you haven’t got a good explanation, then making it static is a mistake.
 
Alain Fallada
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, thank you all for your help.
i just don't understand how to use methods, and classes.
and when to use static and private.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this stage:
  • 1: Use static for the main method and nothing else.
  • 2: Use private for all fields and public for all constructors and methods.
  • This will change when you are more experienced.

    For classes and methods, try the Java tutorials. Note they don’t always make their fields private as you really should.
     
    Jayesh A Lalwani
    Rancher
    Posts: 2756
    32
    Eclipse IDE Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Aside from the static members and making your members private, your code is structured well. It's hard to see what exactly you need to understand, because, as far as I see, this code looks like someone who had a good understanding of modularizing their code.
     
    Suryanarayana murthy
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Please learn about static modifier where to use and where not to use

    Regards
    Surya
     
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12196
    35
    Chrome Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I spent about 2 seconds looking at your code, and would say that it definitely does NOT make sense.

    Why?

    Because there are ZERO comments. Comments may seem like a waste of time at this stage, but trust me, they are vital in every single piece of code you write. Even if it is nothing more than a general statement of what the class/method is for, it needs to be there.

    Next, a variable name like "junk" is not very well named. if it holds junk, then why bother saving it at all? a more descriptive name like "userInput" is MUCH better and tells me immediately what it is for, rather than making me hunt through the code.

    I personally would put in some validation code. If you ask the user to input a value between 1 and 25, you should validate that they did. There are a lot of evil users who will read that direction, and say "I wonder what happens if I put in 87?".
     
    Alain Fallada
    Greenhorn
    Posts: 18
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well Thank you all for your help. i will try to look in youtube to find out how to define and call classes. that is what i have more difficulties.
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 50225
    79
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Suryanarayana murthy welcome to the Ranch
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 50225
    79
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Alain Fallada wrote: . . . i will try to look in youtube to find out . . .
    Careful. some of the things you find might be not at all helpful.
     
    Himanshu bisht bebo
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to ranch , where is goodPattern method and read good coding convention for coding . These is not a good code
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic