i am trying to make a unit converter using javafx - i've been searching around for two days on how can i reduces these if-statements. somehow, i found some similar issue but it didn't help me since i am new with Java - i do not know the right approach in my case.
Hope you guys could help me -
thanks
/**
* CELSIUS TO
*/
Celsius celsius = new Celsius(parseInput);
if(cbOne.getValue().equals("Celsius")) {
if(cbTwo.getValue().equals("Celsius") ) {
showAnswer.setText(celsius.celsiusToCelsius());
}
if(cbTwo.getValue().equals("Fahrenheit")) {
showAnswer.setText(celsius.celsiusToFahrenheit());
}
if(cbTwo.getValue().equals("Kelvin")) {
showAnswer.setText(celsius.celsiusToKelvin());
}
}
/**
* FAHRENHEIT TO
*/
Fahrenheit fahr = new Fahrenheit(parseInput);
if(cbOne.getValue().equals("Fahrenheit") ) {
if(cbTwo.getValue().equals("Celsius") ) {
showAnswer.setText(fahr.fahrenheitToCelsius());
}
if(cbTwo.getValue().equals("Fahrenheit")) {
showAnswer.setText(fahr.fahrenheitToFahrenheit());
}
if(cbTwo.getValue().equals("Kelvin")) {
showAnswer.setText(fahr.fahrenheitToKelvin());
}
}
/**
* KELVIN TO
*/
Kelvin kelvin = new Kelvin(parseInput);
if(cbOne.getValue().equals("Kelvin")) {
if(cbTwo.getValue().equals("Celsius") ) {
showAnswer.setText(kelvin.kelvinToCelsius());
}
if(cbTwo.getValue().equals("Fahrenheit")) {
showAnswer.setText(kelvin.kelvinToFahrenheit());
}
if(cbTwo.getValue().equals("Kelvin")) {
showAnswer.setText(kelvin.kelvinToKelvin());
}
}
}