Skip to content

Instantly share code, notes, and snippets.

@maxov
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxov/23c766eb59345a0c87b7 to your computer and use it in GitHub Desktop.
Save maxov/23c766eb59345a0c87b7 to your computer and use it in GitHub Desktop.
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