So I'm debugging my program and I have to use a few operators. However the values that I'm doing the comparison on are objects of custom classes.
I created this "Money" Class.
public Money(double amount)
{
if (amount < 0)
{
System.out.println(
"Error: Negative amounts of money are not allowed.");
System.exit(0);
}
else
{
long allCents = Math.round(amount*100);
dollars = allCents/100;
cents = allCents%100;
}
}
And I have these errors:
CreditCard.java:55: error: bad operand types for binary operator '<='
if (balance && amount <= creditLimit)
^
first type: Money
second type: Money
CreditCard.java:57: error: bad operand types for binary operator '+'
balance += amount;
^
first type: Money
second type: Money
CreditCard.java:68: error: bad operand types for binary operator '-'
balance -= amount;
^
first type: Money
second type: Money
3 errors
I'm trying to do this operation:
public void charge(Money amount)
{
if (balance && amount <= creditLimit)
{
balance += amount;
}
else
{
System.out.println("The amount to charge exceeds the credit limit and will not be charged.");
}
}
What do I use for these kinds of operators with custom objects?