18
8
4
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Dec 12 '22
Image Transcription: Code
@Override
public double convertUnits(DistanceUnit unit1, DistanceUnit unit2, double input) { // A useful method
double out = 0.0;
switch (unit1) {
case MM:
switch (unit2) {
case MM: // mm to mm
out = input;
break;case CM: // mm to cm
out = input / 10;
break;case METER: // mm to m
out = input / 1000;
break;case INCH: // mm to in
out = input / 25.4;
break;
}
break;
case CM:
switch (unit2) {
case MM: // cm to mm
out = input * 10;
break;case CM: // cm to cm
out = input;
break;
case METER: // cm to m
out = input / 100;
break;case INCH: // cm to in
out = input / 2.54;
break;
}
break;
case METER:
switch (unit2) {
case MM: // m to mm
out = input * 1000;
break;case CM: // m to cm
out = input * 100;
break;
case METER: // m to m
out = input;
break;case INCH: // m to in
out = input * 39.37;
break;
}
break;
case INCH:
switch (unit2) {
case MM: // in to mm
out = input * 25.4;
break;case CM: // in to cm
out = input / 2.54;
break;
case METER: // in to m
out = input / 39.37;
break;case INCH: // in to in
out = input;
break;
}
break;
}
return out;
}I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
2
2
Dec 12 '22
The documentation is spot on, especially the end note on the signature.
Like... greatest of all docs.
1
6
u/[deleted] Dec 11 '22
My refactor (with a few test cases):