Class
Length
java.lang.Object
Length
public class Lengthextends
java.lang.Object
This class constructs and manipulates a
Length object which consists of feet and inches
(package
private) int |
|
(package
private) int |
|
(package
private) int |
Constructor
Summary |
|
Length() |
|
Length(int numberOfFeet,
int numberOfInches) |
|
Length(int numberOfFeet,
int numberOfInches, boolean sign) |
|
Method
Summary |
|
void |
changeBy(Length someLength) |
boolean |
equals(Length aLength) |
private
int |
toInches() |
java.lang.String |
toString() |
Methods
inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode,
notify, notifyAll, wait, wait, wait
|
int numberOfFeet
int numberOfInches
int sign
public Length()
default constructor for objects of class Length
It has no parameters It sets initializes instance variables feet & inches
to 0 by making them parameters in its call to the 2 parameter constructor
public Length(int numberOfFeet,
int numberOfInches)
This
is the two parameter explicit value constructor it sets the attribute variables
to the values passed in through the parameter list and calls the three value
constructor with the sign a positive value (i.e. true)
Parameters:
numberOfFeet - is the object's initial number of feet
numberOfInches - is the object's intial number of
inches
public Length(int numberOfFeet,
int numberOfInches,
boolean sign)
This
is the three parameter explicit value constructor It
needs to set the int attribute for sign
Parameters:
numberOfFeet - is the initial number of feet in the
new object
numberOfInches - is the initial number of inches in the
new object
sign - indicates whether the length is
positive or not (true if it is)
public void changeBy(Length someLength)
This
method alters the calling object's length by adding the parameter object's
length to it. Remember that each Length object has its
own attribute values which it knows about
Parameters:
someLength - is the Length whose attributes are to
effect the change
public boolean equals(Length aLength)
This
method returns true if the calling object's length equals the pararameter
object's length
Parameters:
aLength - is the object being compared to the
calling object
Returns:
a boolean telling whether the lengths are equal or not
public java.lang.String toString()
This
method returns the number of inches in the object's length as a String
Overrides:
toString in class java.lang.Object
Returns:
a String representing the object's length
private int toInches()
This
method returns the equivalent number of inches in the object's Length
Returns:
The
length of the object in inches