View Javadoc
1   package org.djunits.demo.examples;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.MoneyPerMassUnit;
6   import org.djunits.unit.MoneyUnit;
7   import org.djunits.unit.UNITS;
8   import org.djunits.value.vdouble.scalar.Density;
9   import org.djunits.value.vdouble.scalar.Mass;
10  import org.djunits.value.vdouble.scalar.Money;
11  import org.djunits.value.vdouble.scalar.MoneyPerMass;
12  import org.djunits.value.vdouble.scalar.Volume;
13  
14  /**
15   * This Java code demonstrates demonstrates the use of Money units in DJUNITS.
16   * <p>
17   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
19   * <p>
20   * @version $Revision: 257 $, $LastChangedDate: 2018-01-28 03:20:38 +0100 (Sun, 28 Jan 2018) $, by $Author: averbraeck $, initial version 7 sep. 2015 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
23   */
24  public final class Currency implements UNITS
25  {
26      /** */
27      private Currency()
28      {
29          // utility constructor.
30      }
31      
32      /**
33       * Create some scalar values to demonstrate conversion from and to related units.
34       * @param args String[]; the command line arguments; not used
35       */
36      public static void main(final String[] args)
37      {
38          Locale.setDefault(Locale.US); // Ensure that floating point values are printed using a dot (".")
39          MoneyUnit.setStandardUnit(MoneyUnit.EUR);
40          Density density = new Density(150.0, KG_PER_METER_3);
41          MoneyPerMass costPerKG = new MoneyPerMass(20.0, MoneyPerMassUnit.EUR_PER_KILOGRAM);
42          System.out.println("standard price " + costPerKG); // prints 20.000�/kg
43          Money startupCost = new Money(100.0, MoneyUnit.EUR);
44          Volume volume = new Volume(300.0, LITER);
45          Mass totalWeight = volume.multiplyBy(density);
46          System.out.println("weight of " + volume + " is " + totalWeight); // prints 45.000kg
47          Money totalCost = startupCost.plus(totalWeight.multiplyBy(costPerKG));
48          System.out.println("total cost " + totalCost); // prints 1000.000�
49      }
50  }