📄 areaunit.java
字号:
package ranab.unit;
/**
* Area unit converter class.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class AreaUnit extends BaseUnit {
private final static String[] UNITS = {
"square inches",
"square feet",
"square yards",
"square miles",
"acres",
"square cm",
"square meters",
"square km",
"hectares"
};
// base weight unit is square meters
private final static double[] M2_TABLE = {
1550.0031000062001,
10.763910416709722,
1.1959900463010802,
3.8610215854781256e-7,
0.0002471053814671653,
10000,
1,
0.000001,
0.0001
};
/**
* Get all the possible units.
*/
public String[] getAllUnits() {
return UNITS;
}
/**
* Convert one unit from another
*/
public String convertUnit(String value, int from, int to) throws UnitException {
double inVal = getDoubleValue(value);
double outVal = inVal*M2_TABLE[to]/M2_TABLE[from];
return String.valueOf(outVal);
}
/**
* Return unit type.
*/
public String toString() {
return "Area";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -