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

Whats wrong with my Implementation

 
Ranch Hand
Posts: 99
2
  • Mark post as helpful
  • send pies
  • 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: 6187
157
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • 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: 68044
258
  • Mark post as helpful
  • send pies
  • 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.
 
It's exactly the same and completely different as this tiny 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!