Last active
August 29, 2015 14:11
-
-
Save maxov/23c766eb59345a0c87b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Equation { | |
abstract double get(double x); | |
public Equation compose(Equation that) { | |
return new Equation { | |
double get(double x) { | |
this.get(that.get(x)); | |
} | |
} | |
} | |
} | |
class LinearEquation extends Equation { | |
private final double constant; | |
private final double slope; | |
public LinearEquation(double constant, double slope) { | |
this.constant = constant; | |
this.slope = slope; | |
} | |
double get(double x) { | |
return slope * x + constant; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment