This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Consider my new CodeRanchUser class

 
Ranch Foreman
Posts: 74
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My new project, I did my best. Critique welcome  

 
Saloon Keeper
Posts: 6923
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

  • All upper case names are usually reserved for constants, as in static final. Your ID_COUNTER technically doesn't qualify though it does make it stand out in the code.
  • I would prefer that 'author' had been named 'isAuthor'. I know that's what the getter is but using 'is' also helps with variable names.
  • Line 68, use equals() and not '=='.
  • Need a getter for yearJoined.
  •  
    Carey Brown
    Saloon Keeper
    Posts: 6923
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
     
    Carey Brown
    Saloon Keeper
    Posts: 6923
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The rank of an individual should be handled as an enum.
     
    Marshal
    Posts: 25183
    64
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:The rank of an individual should be handled as an enum.



    Not necessarily; notice that Mike has "author & internet detective" as one of the possibilities.
     
    Carey Brown
    Saloon Keeper
    Posts: 6923
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    should be

    Management of a collection of CodeRanchUser objects should be encapsulated in its own class, e.g. CodeRanchUsers (plural).

    Line 16, don't need toString() call.

    Line 30, why the trailing space?

    Users should be added through CodeRanchUsers which should return an ID. From there on all access should be via the ID and not an ordinal position in the List because CodeRanchUsers may or may not choose to implement a List. So the use of get(3), for example, would be replaced by a retrieval by ID.
     
    Carey Brown
    Saloon Keeper
    Posts: 6923
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Paul Clapham wrote:

    Carey Brown wrote:The rank of an individual should be handled as an enum.

    Not necessarily; notice that Mike has "author & internet detective" as one of the possibilities.


    I submit that the rank is an exclusive value and an enum is appropriate. isAuthor and isDetective may be additional boolean qualifiers.
     
    Mike Savvy
    Ranch Foreman
    Posts: 74
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have changed so far, but do not really understand what/how exactly CodeRanchUsers class should be? Carey Brown
     
    Master Rancher
    Posts: 259
    13
    Eclipse IDE C++ Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    to shorten up the code these things should just be 1 line.


    also, can you explain to me what this line is, do we have pointers in java now?
    ( i know its probably a lambda of some sort )
     
    Marshal
    Posts: 68044
    258
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Urma Fusco and Mycroft Modern Java in Action (Manning) or Java8 in Action (=same book, older edition).
    Java™ Tutorials section.
     
    Mike Savvy
    Ranch Foreman
    Posts: 74
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:Urma Fusco and Mycroft Modern Java in Action (Manning) or Java8 in Action (=same book, older edition).
    Java™ Tutorials section.


    What do you mean? For CodeRunchUsers?
     
    Campbell Ritchie
    Marshal
    Posts: 68044
    258
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It was a reply to S Fox's post. Useful resources.
     
    Bartender
    Posts: 3760
    154
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    S Fox wrote:also, can you explain to me what this line is, do we have pointers in java now?
    ( i know its probably a lambda of some sort )



    Yes it is. If you look at Mike's definition of the print method, you see that the second parameter is a Predicate. u -> u.isMarshall() is indeed a Predicate.

    Petite question for Mike:
    if you want to print ALL members, what Predicate would you use? Or you could overload the print-method, leaving out that Predicate as parameter. What would you prefer?
     
    Marshal
    Posts: 6824
    182
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you want to practice streams, you could turn the print method into a stream.
     
    Mike Savvy
    Ranch Foreman
    Posts: 74
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Okay, I was confused because there is not about lambdas, but about nested classes    Campbell
     
    Mike Savvy
    Ranch Foreman
    Posts: 74
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Piet Souris and Knute Snortum I am not sure I must know about, since it is not in scope of OCAJ SE8 exam, which I will take this week. But I can back to this suggestions after exam
     
    Campbell Ritchie
    Marshal
    Posts: 68044
    258
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That section includes λs. Look on the left of that link. I thought SF would do better to look at the whole section.
     
    Piet Souris
    Bartender
    Posts: 3760
    154
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Okay, Mike.

    Success with your exam!
     
    Carey Brown
    Saloon Keeper
    Posts: 6923
    65
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is along the lines of what I was thinking of for CodeRanchUsers, keeping future persistence in mind. Others may have some feed back on this.
     
    Knute Snortum
    Marshal
    Posts: 6824
    182
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here's what I was thinking of for the print method:
     
    I am mighty! And this is a mighty small ad:
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!