0

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)

JoseK
  • 31,141
  • 14
  • 104
  • 131
supersaiyan
  • 1,670
  • 5
  • 16
  • 36
  • That ratio sounds like it should be established by the business rules. It should be represented in your code by a class variable. – Ted Hopp Apr 17 '13 at 04:02

2 Answers2

2

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.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

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.

Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116
  • You only need to worry about the bottom line. That's the result. I was just showing the algebra used to get from your equation to the solution. – Silvio Mayolo Apr 17 '13 at 04:08