public class Length extends Objectimplements Comparable <Length >
Length object includes a value and a unit.
A set of common units of length are included in this class.
| Modifier and Type | Class and Description |
|---|---|
static class |
Length
A unit of measurement for length.
|
| Modifier and Type | Field and Description |
|---|---|
static Length |
CENTIMETER
The unit definition of a centimeter.
|
static Length |
DECIMETER
The unit definition of a decimeter.
|
static Length |
FOOT
The unit definition of a foot.
|
static Length |
INCH
The unit definition of an inch.
|
static Length |
KILOMETER
The unit definition of a kilometer.
|
static Length |
METER
The unit definition of a meter.
|
static Length |
MICROMETER
The unit definition of a micrometer.
|
static Length |
MILE
The unit definition of a mile.
|
static Length |
MILLIMETER
The unit definition of a millimeter.
|
static Length |
YARD
The unit definition of a yard.
|
| Constructor and Description |
|---|
Length(double v, Length
Create a new
Length object.
|
Length(Length
Clones a
Length object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Length
Add the argument to this
Length object.
|
Object |
clone()
|
int |
compareTo(Length
Compares the distance of this
Length object with another.
|
boolean |
equals(Object
This returns
true if two
Length objects measure the same distance, regardless of their units.
|
Length |
getUnit()
Returns the unit of this
Length object.
|
static Length |
getUnitByName(String
Returns a unit associated with a given name.
|
static Length |
getUnits()
Returns all the available units.
|
double |
getValue(Length
Returns the numeric value of this distance in the unit specified.
|
void |
setUnit(Length
Changes the unit of this length, but the actual distance measured remains the same.
|
void |
setValue(double v, Length
Redefine this
Length object.
|
void |
subtract(Length
Subtracts the argument from this
Length object.
|
String |
toString()
Returns the value of this length followed by the unit abbreviation.
|
public static final Length.Unit KILOMETER
public static final Length.Unit METER
public static final Length.Unit DECIMETER
public static final Length.Unit CENTIMETER
public static final Length.Unit MILLIMETER
public static final Length.Unit MICROMETER
public static final Length.Unit INCH
public static final Length.Unit FOOT
public static final Length.Unit MILE
public static final Length.Unit YARD
public Length(double v,
Length.Unit u)
Length object.
v - the number value of this length.
u - the units that value is measured in.
public Length(Lengthl)
Length object.
public static Length.Unit [] getUnits()
public Objectclone()
public void setUnit(Length.Unit u2)
setUnit(Length.METER), then this object now represents "1 m".)
public static Length.Unit getUnitByName(String name)
This looks for abbreviations and full spellings of unit names.
name - a name for a unit. This is not case sensitive.
null if no units are found.
public boolean equals(Objectobj)
true if two
Length objects measure the same distance, regardless of their units.
public double getValue(Length.Unit u)
u - the unit to get the value in
public void setValue(double v,
Length.Unit u)
Length object.
public void add(Lengthl)
Length object. The units of both objects are unchanged.
public void subtract(Lengthl)
Length object. The units of both objects are unchanged.
public Length.Unit getUnit()
Length object.
public int compareTo(Lengthl)
Length object with another.
public StringtoString()