feat: add temperature unit conversions (#5315)

Co-authored-by: Bama Charan Chhandogi <b.c.chhandogi@gmail.com>
This commit is contained in:
Piotr Idzik
2024-08-22 08:43:52 +02:00
committed by GitHub
parent 5149051e95
commit 07dbc51e1b
5 changed files with 189 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package com.thealgorithms.conversions;
public final class AffineConverter {
private final double slope;
private final double intercept;
public AffineConverter(final double inSlope, final double inIntercept) {
slope = inSlope;
intercept = inIntercept;
}
public double convert(final double inValue) {
return slope * inValue + intercept;
}
public AffineConverter invert() {
assert slope != 0.0;
return new AffineConverter(1.0 / slope, -intercept / slope);
}
public AffineConverter compose(final AffineConverter other) {
return new AffineConverter(slope * other.slope, slope * other.intercept + intercept);
}
}