added uebung07 angabe
This commit is contained in:
28
uebung07/src/quantities/plain/Quantity.java
Normal file
28
uebung07/src/quantities/plain/Quantity.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package quantities.plain;
|
||||
|
||||
public abstract class Quantity {
|
||||
public final double value;
|
||||
public final Unit unit;
|
||||
|
||||
protected Quantity(double value, Unit unit) {
|
||||
this.value = value;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public double getBaseValue() {
|
||||
return value * unit.baseFactor;
|
||||
}
|
||||
|
||||
public double value(Unit unit) {
|
||||
return getBaseValue() / unit.baseFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + " " + unit;
|
||||
}
|
||||
|
||||
public String format(String fmt, Unit unit) {
|
||||
return String.format(fmt, value(unit), unit);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user