Android Open Source - Dilution Core






From Project

Back to project page Dilution.

License

The source code is released under:

MIT License

If you think the Android project Dilution listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package sk.fotopriestor.dilution.core;
/*from   ww w  .  j  a v  a  2s. c o m*/
import java.math.BigDecimal;
import java.math.MathContext;

/**
 * Mathematically this relationship can be shown in the equation:<br>
 * C1*V1 = C2*V2<br>
 * Where:
 * <ul>
 * <li>C1 Initial concentration or molarity.
 * <li>V1 Initial volume.
 * <li>C2 Final concentration or molarity.
 * <li>V2 Final volume
 * </ul>
 * 
 * @author peter
 * TODO list:
 * - premeny jednotiek, koeficienty
 * - historia
 * - swap hodnot
 * - ulozit oblubenu
 * - urobit to pekne na tabletoch aj mobiloch
 */
public class Core {
  public static final MathContext mc = MathContext.DECIMAL64;
  public static final int KILO = 3;
  public static final int ONE = 1;
  public static final int MILLI = -3;
  public static final int MICRO = -6;
  public static final int NANO = -9;
  public static final int PICO = -12;

  /**
   * Calculate the result of dilution equation for one unknown:
   * <code>C_1\times V_1 = C_2\times V_2</code>
   * 
   * @param c
   *            The concentration C_1
   * @param v
   *            The volume V_1
   * @param third
   *            The `third' value, i.e. C_2 or V_2
   * @return The value of `unknown', i.e. V_2 if third is C_2 and C_2 if third
   *         is V_2
   */
  public static Value dilution(Value c, Value v, Value third) {
    BigDecimal lhsNum = c.getValue().multiply(v.getValue(), mc);
    BigDecimal resNum = lhsNum.divide(third.getValue(), mc);
    int coef = c.getUnitCoef() + v.getUnitCoef() - third.getUnitCoef();
    return new Value(resNum, coef);
  }

}




Java Source Code List

sk.fotopriestor.dilution.MainActivity.java
sk.fotopriestor.dilution.core.Core.java
sk.fotopriestor.dilution.core.Value.java