Need help calculating Money

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alicat6
    New Member
    • Mar 2008
    • 1

    Need help calculating Money

    Hello,

    I need some help writing code that will calculate late fees. The code needs to return 0.0 if the item is not overdue and caluclate a late fee of .75 for every day overdue. Below is what I have so far. The problem I am having is trying to get the Money object to multiply by the double or int object . I also tried to increment the fee for each day it is overdue, but that doesn't work either. Any suggestions?

    Code:
     public Money calculateFees(GregorianCalendar currentDate)
        {
            overdue = currentDate.compareTo(dueDate);
            
            if (overdue <= 0)
            {
                return NO_FEE;
            }
            
            for (int i = 0; i <= overdue; i++)
            {
                if(overdue > 0)
                {
                    fee = OVERDUE_FEE++;
                }
                return fee;
            }
            
        }
  • rodeoval
    New Member
    • May 2007
    • 15

    #2
    If I am correct, I guess the method compareTo only returns one of the values 1 ,0,-1 based on the compared dates.It does not return an int which is equal to the overdue amount of days or time.You can only use that method to check whether its overdue or not.Thus using 'overdue' in for loop to increment the fee with overdue_fee is meaningless.
    All the same if you are using a loop to calculate the fee I think the code should be changed as follows.
    method()
    {
    if (overdue <= 0)
    {
    return NO_FEE;
    }

    //overdue is an int which denotes the number of overdue dates
    for (int i = 0; i <= overdue; i++)
    {
    fee += OVERDUE_FEE;
    }

    return fee;
    }

    Comment

    Working...