1

I am developing a Java application, its about converting Mathcad worksheet to Java application. Can anyone know/suggest how to write units(newton, pascal, mm, kg)in java code?

Example:1?

double var1 = 10*newton/mm;//looking for a way to write the code in this format.
double var2 = 5*mmpower2;
double var = var1/var2;
double var = ?

Example: 2?

double var1 = 90degress-tan(60)*Radian;
double var1 = ?
Vijay Vennapusa
  • 169
  • 3
  • 15

2 Answers2

3

You could use the Javax.units package, especially the Java Unit Class.

This is a well-studied problem and for any non-trivial program you should always use an existing units library.

Mike Vella
  • 10,187
  • 14
  • 59
  • 86
0

Neither of your examples are sensible Java.

You want to implement the Martin Fowler Analysis Patterns idea of Quantity with units.

There are libraries that exist, like JScience, but I don't know if they're in widespread use.

duffymo
  • 305,152
  • 44
  • 369
  • 561