• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

collection exercize

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have six java source files that together make up a simple store and inventory system I'm working on. It's supposedly to teach me about collections.
I have two interfaces provided for me, StoreInterface and InventoryItemInterface.
I have a class StoreUI (partially created) which is the main arg and main file the user interacts with to do several functions, like add/delete an item to the store inventory, display the entire inventory, etc. I have a SimpleInput class that contains code that helps StoreUI take keyboard input from the user.
I have two classes I'm designing from scratch. One, Store, defines the methods from StoreInterface. The second, InventoryItem, defines the methods from InventoryItemInterface.
My dilemma: I have this code I've created so far for Store.java and I'm getting confused with the returns from the methods. How do I implement a return with several things going on in a method. In particular for now

This file is to define methods found in this interface StoreInterface.java

This file is the main user interface file StoreIU.java

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 17, 2004: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nobody else is answering your question, so I'll throw out a few thoughts:
1) Don't cross post.
2) I'm not sure what problems/questions you are asking here.
Are you having problems with the syntax of the Java language for returning values from functions? Having problems understanding how return values relate to the parameters passed to a function? Having problems collaborating between your 6 classes/files to compute an answer which is returned from a function?
Be more descriptive with your inquiry so we can help you more.
 
Marc Kryzhan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My primary question is does a method definition for an interface need to specify 'return' and some return, even if it's just return null;?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, first of all, null is a value. When we declare a function like this:
public String getJobTitle() {...}
String is the TYPE (aka Class) of object that will be returned by the function. We return "null", since "null" is an actual value for Object-derived classes.
If you have functions that won't need to return any value, you specify "void" in place of the class of object that can be returned:
public void doSomething() {..}
The method doSomething won't return any value. To exit the function prematurely (as opposed to just finishing the whole thing), you simply use the statement "return" as in:

I hope that helps you out more. (To answer you actual question finally, if you specify "return null" somewhere in the method, then you need to specify an actual Object-derived class to return from the method, opposed to "return void".)
 
Marc Kryzhan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand. Thank you for your very clear example and answer. As I work my way through this problem I may have a question or two, but I will keep them clear and brief also. It's like playing windwalker and needing a hint here or there.
 
Water! People swim in water! Even tiny ads swim in water:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic