testing a Money object

I want to test a money object to ensure it is not negative and if it is then throw an exception. This comes up with an error, can you figure it out for me?

publicstaticvoid isnotNegative(Money cash1)

{

if (cash1 < 0)

{

thrownew IllegalArgumentException();

}

}

operator < cannot be applied to Money,int

[701 byte] By [javastudent07a] at [2007-11-26 18:23:19]
# 1
You can't compare an Object like you can an int. Is there a getValue() method (or something similar) in the Money class?
CaptainMorgan08a at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...
# 2
It uses the Java Money class (if that makes sense....I dont know if I worded that correctly). Any idea of how I can test it?
javastudent07a at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...
# 3
I know. An int is a primitive, a Money is an object. You can't compare the two, although there is probably a method in the Money class that returns an int, which can be compared to another int. It's hard to say without seeing the code for the Money class.
CaptainMorgan08a at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...
# 4
Maybe it's if (cash1.amount() < 0)
flybuzza at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...
# 5
nope, that didn't compile.
javastudent07a at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...
# 6
> nope, that didn't compile.We can't tell you because we don't have the code for the Money class!
CaptainMorgan08a at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...
# 7

Ok, I got this to work:

public static void isnotNegative(Money cash1)

{

if (cash1.isNegative())

{

throw new IllegalArgumentException();

}

}

It didn't compile the first time I tried it. I guess I typed something wrong before.

javastudent07a at 2007-7-9 5:57:12 > top of Java-index,Java Essentials,New To Java...