Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

missing return statement  RSS feed

 
callam falconer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

I am currently trying to complete this https://www.dropbox.com/s/vfaz5jhjmbm2p2v/BlueJHelpMe.doc?dl=0tassignment[/url] (It's overdue because I have been stuck on what to do for the last day)

I have completed the Product class, and I am currently completing the Store class.




So as you can see I've mostly completed Product. First of all, if someone would be so kind to check this over and point out anything I did wrong, i'd appreciate it. I am having trouble with the



BlueJ is saying "missing return statement" and I have no idea how to fix it. If anyone could point me in the right direction I'd appreciate it. Also, I'll post my store class in the comments and i have an error there too...
 
callam falconer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



(NOTE: In my class at this current point in time we were not allowed to add Arrays so please forgive me for the unneccesary amount of if statements!)

When ever I compile this, the bottom bit (getOrder) will never find the getOrder in Product class. I can't wrap my head around this as I thought I was declaring the method well in the Product class.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
callam falconer wrote:I am having trouble with the



BlueJ is saying "missing return statement" and I have no idea how to fix it. If anyone could point me in the right direction I'd appreciate it. Also, I'll post my store class in the comments and i have an error there too...


If the "if" condition block executes (meaning else doesn't execute), then what should the method return?

Henry
 
callam falconer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
callam falconer wrote:I am having trouble with the



BlueJ is saying "missing return statement" and I have no idea how to fix it. If anyone could point me in the right direction I'd appreciate it. Also, I'll post my store class in the comments and i have an error there too...


If the "if" condition block executes (meaning else doesn't execute), then what should the method return?

Henry


hi Henry

I'm not sure what you mean (very new!) I'm trying to return 0 as the assignment tells me. Can you explain in further detail?

Thanks!
 
Paul Clapham
Sheriff
Posts: 22531
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. The assignment says "If (such and such) is true then return zero". And yes, you did that. But what if (such and such) isn't true? You have to return something, that's a rule of Java. (Hence the compiler error message.) So, what should you return? The assignment doesn't explicitly say what you should return so it's up to you to read between the lines in the assignment.

(By the way it's normal for programmers to work from specs which aren't quite perfect. That's what you have to do here.)

EDIT: Actually now that I reread the specs, they do explicitly say what you should return. Read them again.
 
callam falconer
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Right. The assignment says "If (such and such) is true then return zero". And yes, you did that. But what if (such and such) isn't true? You have to return something, that's a rule of Java. (Hence the compiler error message.) So, what should you return? The assignment doesn't explicitly say what you should return so it's up to you to read between the lines in the assignment.

(By the way it's normal for programmers to work from specs which aren't quite perfect. That's what you have to do here.)

EDIT: Actually now that I reread the specs, they do explicitly say what you should return. Read them again.


Thanks so much, it took me a bit to understand but I eventually got it and wooo no Syntax errors!

I posted the exact same thing on Reddit and Stackoverflow and received some shade from more experienced programmers, I'm glad I joined a community that is friendly towards noobs.

Again, thanks a lot!
 
Paul Clapham
Sheriff
Posts: 22531
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, StackOverflow does have that reputation. Anyway, glad you're back on track.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!