Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 7068
165
  • 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: 73738
332
  • 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.
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic