Carey Brown

Saloon Keeper
+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
Forum Moderator
Carey Brown currently moderates these forums:
Colorado, USA
Cows and Likes
Cows
Total received
71
In last 30 days
0
Total given
5
Likes
Total received
1494
Received in last 30 days
1
Total given
234
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carey Brown

Just to clarify a few things. You don't need to assign the difference to a variable named "timeDifference" in order to be in sync with the calling code. You could name it anything you want here and it wouldn't impact the caller. In fact, you don't need any variable at all, you can just return it like this:
Similarly, the name of your parameter "start_date" doesn't need to match the name used in the calling code. You could have named it anything you wanted here with no impact to the caller.
1 hour ago
Note that you are currently not doing anything if an exception is thrown. I suggest you fix this ASAP.
6 hours ago
You have a couple of ways to address the issue:
Move the code inside the try block.
Declare "timeDifference" outside the try block.

6 hours ago

Bob Matthews wrote:

Remember what I said about the "scope" of variables? On line 2 you have "timeDifference" inside the scope of a try block. On line 9 you have the same variable name but in a different scope. They can't be the same variable.
6 hours ago
Hope everything's ok now. I'm calling it a night.
18 hours ago

Bob Matthews wrote:should I replace timeDifference with difference_In_Time ?

Doesn't matter what you call it but lines 5 and 7 must match.

Bob Matthews wrote:No - the method timeDifferences is not in a file called timeDifferences.java

Then that means you probably have an inner class. Is it defined INSIDE the definition of another class?

Right now your "Timedifferences" class has only one method that should be static but because it is not defined as a top-level class the compiler is complaining. You might want to move the findDifference method out to your top-level class so that static is not a problem and then call it using just findDifference(...) with no Timedifferences in front.
18 hours ago
Is class "Timedifferences" defined inside a file named "Timedifferences.java" ?
18 hours ago

Bob Matthews wrote:

Bob, it's hard for me to stay in sync with you and the changes you're making.  In this post when you call findDifference() it is assigning it to "timeDifference". It knows nothing of what the variable may have been named inside the method.
18 hours ago

Bob Matthews wrote:

difference_In_Time = findDifference    

You may have two variables declared in your code with the same name but that doesn't mean that they are the same variable. It depends on the "scope" of the variable. "difference_In_Time" in your method is "local" to that method only.
19 hours ago
Ah. Is your Timedifferences class an inner class?
19 hours ago
Show me the code and show me the error message.
19 hours ago

Bob Matthews wrote:new error:

cannot make a static reference to the non-static method findDifference(String, String) from the type TimeDifferences

You are loading one variable on line 5 but printing a different one on line 7.
19 hours ago

Carey Brown wrote:I don't know what your full intentions were for the "timedifferences" class but as it stands right now it looks like a utility class. So the method findDifference() doesn't really require that there be an object so it should be declared "static".

19 hours ago

Bob Matthews wrote:calling code...........

error: the method findDifference(String, String) is not applicable for the arguments (Date,Date)


You are  trying to print "difference_In_Time" but that variable is not part of this method. The variable you've declared here is "timeDifference".
19 hours ago
Java naming conventions say that all variables must begin with a lower case letter and use camel case. The underscore (_) should not be used in variable names but can be used in constant names.
19 hours ago