Building Parsers with Java

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));

  


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
 

Constructor Detail

LinearCalculator

public LinearCalculator(double xFrom,
                        double xTo,
                        double yFrom,
                        double yTo)
Create a LinearCalculator from known points on two scales.
Parameters:
double - xFrom
double - xTo
double - yFrom
double - yTo
Method Detail

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

by Steve Metsker