File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes collection exercize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "collection exercize" Watch "collection exercize" New topic
Author

collection exercize

Marc Kryzhan
Greenhorn

Joined: Mar 17, 2004
Posts: 14
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 ]

Newbee to java.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Marc Kryzhan
Greenhorn

Joined: Mar 17, 2004
Posts: 14
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

Joined: May 29, 2003
Posts: 1258
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

Joined: Mar 17, 2004
Posts: 14
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: collection exercize