• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Consider my new CodeRanchUser class

 
Rancher
Posts: 163
5
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My new project, I did my best. Critique welcome  

 
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10930
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
  • yearJoined should be private.
  • userID should be private.
  •  
    Carey Brown
    Saloon Keeper
    Posts: 10930
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The rank of an individual should be handled as an enum.
     
    Sheriff
    Posts: 28328
    96
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 10930
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 10930
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Rancher
    Posts: 163
    5
    Eclipse IDE Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I have changed so far, but do not really understand what/how exactly CodeRanchUsers class should be? Carey Brown
     
    Rancher
    Posts: 285
    14
    Eclipse IDE C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 79969
    396
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Rancher
    Posts: 163
    5
    Eclipse IDE Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 79969
    396
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It was a reply to S Fox's post. Useful resources.
     
    Bartender
    Posts: 5567
    213
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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?
     
    Sheriff
    Posts: 7125
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you want to practice streams, you could turn the print method into a stream.
     
    Mike Savvy
    Rancher
    Posts: 163
    5
    Eclipse IDE Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay, I was confused because there is not about lambdas, but about nested classes    Campbell
     
    Mike Savvy
    Rancher
    Posts: 163
    5
    Eclipse IDE Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 79969
    396
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 5567
    213
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay, Mike.

    Success with your exam!
     
    Carey Brown
    Saloon Keeper
    Posts: 10930
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Sheriff
    Posts: 7125
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Here's what I was thinking of for the print method:
     
    The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic