"per unit" logic in java [closed]

-3

How can be a method to return the following:

Knowing that 220 equals 0.3275 and that with each addition of 0.0049 in the value of 0.3275, it will increase by one unit the 220, or every decrease of 0.0049 in the value of 0.3275 will reduce by one unit the 220. How to assemble one method that receives the value of 0.3275, for example and returns me 220, having this factor of 0.0049?

    
asked by anonymous 16.08.2017 / 19:38

1 answer

2

Although the problem is a programming logic problem and not a programming problem, I've made an example code for you to adapt.

    public int calcula(double valor) {
            double unidade = 0.0049; // valor da unidade
            double valorFixo = 0.3275; // valor correspondente a 220 

            // captura a diferença e soma com o 220
            return (int) ((valor - valorFixo ) / unidade) + 220;
    }

Explaining the code:

First you must get the difference between the value informed and the value that we have

    (valor - 0.3275)

After this it is necessary to know how many units this value represents

    (valor - 0.3275) / 0.0049

So just add up to 220 and you have the value you want

    ((valor - 0.3275) / 0.0049) + 220
    
16.08.2017 / 20:13