• 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

Whats wrong with my Implementation

 
Ranch Hand
Posts: 130
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am working on this question from https://stepik.org/lesson/77968/step/5?unit=54819

This is the question

This is the code template provided.


This is my current implementation

But I am stacked with the method findAccountByOwnerId(), the problem is with returning the value from the method. I do not know what am doing wrong here. Line 30 gives me an error.
Any help will be appreciated.
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A method with a return value must in all cases return a value. Here, it may not, if there is no account with ID id. You may assume that there will always be such an account, but you need to convince the compiler that it will always have an Account object to return (or possibly return null otherwise).

Don't write a loop like this, without enclosing braces. My personal rule is that I *may* omit the braces if the for or if contains only a single line of code, but I rarely do. Probably rather sooner than later the time will come to add a second statement, at which point you need to remember to add braces anyway. Plus, it makes the code clearer to read for other people, or yourself, six months down the road.
 
Marshal
Posts: 79974
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:. . . Don't write a loop like this, without enclosing braces. . . . .

Especially not if you indent the code incorrectly.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
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