wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Using a method to return different string depending on situation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using a method to return different string depending on situation" Watch "Using a method to return different string depending on situation" New topic
Author

Using a method to return different string depending on situation

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
So far there is a video class that contains a method to check in a movie


I'm creating a class customer that will keep count of videos and what videos are checked in and out
that belong to the customer. So I want the result to decrement/increment the video from the store
while simultaneously increment/decrement the video to the customers account. My question is
can I use the same method videoCheckIn from the video class and somehow display a different message
when the video is not available such as "this video is not on the customer's account" or will I have
to create a whole new method in my customer class almost exactly the same with a different s.o.p ("string")?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

You could pass what ever message you want to be displayed as a method parameter.


Mohamed Sanaulla | My Blog
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
Ok I'll have to look up the syntax on how to write the code for that but I think I understand what your saying! This brings me to another question, if I use this same method from the video class will it keep a list of the movies the customer is checking out just
like it does for keeping track of the video's in the store from the infile data file and apply it to this customer's account with XXX id number?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

I wasnt able to completely grasp your implementation, but have managed to let you know how to go about with your requirement. From what I see- I was thinking if the code structure would be as follows:


The above code is a very basic structure I could think of. You can improvise it. I am thinking if there's some flaw with the design in terms of- loose coupling and high cohesion.
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
This is what I have, If I understand what your saying I would have to manipulate my videoCheckOut method to be able to print "The customer does not have this video" if the video is not in the customers list. On the other side of things the same method used for the list of video's in the store videoList.videoCheckout would come out with a message saying "The store does not have this video."

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using a method to return different string depending on situation