Question

The formula that I want to convert in java is

Over limit Cash Deposit Fee = [(Input $ cash deposit) – ($ Cash deposits included in plan)] / 1000 * (price/each extra $1000 deposited)

The code that I am writing is

int inputCash = 50;
int cashDepsitFromPlan = 40;
int cashDepositOverLimitFee = 2.5;

cashDepositOverLimit = (double) ((inputCash -cashDepsitFromPlan) / 1000) * ???;

how do I find ???(price/each extra $1000 deposited)

Was it helpful?

Solution

If you're working with floating point numbers, you may want to reconsider the use of the int data type.

This, for a start, is going to cause all sorts of grief:

int cashDepositOverLimitFee = 2.5;

You're better off using double for everything.

In terms of finding the unknown variable here, that's something specific to your business rules, which aren't shown here.

I'd hazard a guess that the price/$1000 figure is intimately related to your cashDepositOverLimitFee variable such as it being $2.50 for every extra $1000.

That would make the equation:

                       inputCash - cashDepsitFromPlan
cashDepositOverLimit = ------------------------------ * cashDepositOverLimitFee
                                   1000

which makes sense. The first term on the right hand side is the number of excess $1000 lots you've deposited over and above the plan. You would multiply that by a fee rate (like $2.50 or 2.5%) to get the actual fee.

However, as stated, we can't tell whether it's $2.50 or 2.5% based on what we've seen. You'll have to go back to the business to be certain.

OTHER TIPS

You have to algebraically manipulate the equation to solve for that.

cashDepositOverLimitFee = (double) ((inputCash -cashDepsitFromPlan) / 1000) * ???
cashDepositOverLimitFee*1000 = (double) (inputCash -cashDepsitFromPlan) * ???
(cashDepositOverLimitFee*1000) / (double) (inputCash -cashDepsitFromPlan) = ???
??? = (cashDepositOverLimitFee*1000) / (double) (inputCash -cashDepsitFromPlan)

Note that the (double) cast must remain in order to ensure a floating point result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top