sjm.utensil
Class LinearCalculator
java.lang.Object
|
+--sjm.utensil.LinearCalculator
- Direct Known Subclasses:
- LimitingLinearCalculator
- public class LinearCalculator
- extends java.lang.Object
A LinearCalculator models two variables that vary
linearly with each other.
For example, Fahrenheit and Celsius temperate scales vary
linearly. Fahrenheit temperature varies from 32 to 212 as
Celsius varies 0 to 100. A LinearCalculator can model the
whole scale, if it is created as:
LinearCalculator lc =
new LinearCalculator(32, 212, 0, 100);
System.out.println(lc.calculateYforGivenX(68));
- Version:
- 1.0
- Author:
- Steven J. Metsker
Field Summary |
(package private) double |
xFrom
|
(package private) double |
xTo
|
(package private) double |
yFrom
|
(package private) double |
yTo
|
Constructor Summary |
LinearCalculator(double xFrom,
double xTo,
double yFrom,
double yTo)
Create a LinearCalculator from known points on two scales. |
Method Summary |
double |
calculateXforGivenY(double y)
Return the value on the first scale, corresponding to the given
value on the second scale. |
double |
calculateYforGivenX(double x)
Return the value on the second scale, corresponding to the given
value on the first scale. |
static void |
main(java.lang.String[] args)
Show the example in the class comment. |
java.lang.String |
toString()
Return a textual description of this object. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
xFrom
double xFrom
xTo
double xTo
yFrom
double yFrom
yTo
double yTo
LinearCalculator
public LinearCalculator(double xFrom,
double xTo,
double yFrom,
double yTo)
- Create a LinearCalculator from known points on two scales.
- Parameters:
double
- xFromdouble
- xTodouble
- yFromdouble
- yTo
calculateXforGivenY
public double calculateXforGivenY(double y)
- Return the value on the first scale, corresponding to the given
value on the second scale.
- Returns:
- the value on the first scale, corresponding to the given
value on the second scale
calculateYforGivenX
public double calculateYforGivenX(double x)
- Return the value on the second scale, corresponding to the given
value on the first scale.
- Returns:
- the value on the second scale, corresponding to the given
value on the first scale
main
public static void main(java.lang.String[] args)
- Show the example in the class comment.
- Parameters:
args
- ignored.
toString
public java.lang.String toString()
- Return a textual description of this object.
- Overrides:
toString
in class java.lang.Object
- Returns:
- a textual description of this object