I'm creating a PV = nRT calculator that has the user enter any of the three given variables. Without the use of a button, the program will automatically detect that three variables have been given and will calculate the fourth missing variable automatically. This is my code so far:
Thread calculate = new Thread(new Runnable() {
@Override
public void run() {
try {
if (Calculations.isCalcable(pressure.getText().toString(),
volume.getText().toString(),
moles.getText().toString(),
temperature.getText().toString()) == true) {
if (pressure.getText().toString().length() == 0) {
pressure.setText("1010");
} else if (volume.getText().toString().length() == 0) {
volume.setText("1010");
} else if (moles.getText().toString().length() == 0) {
moles.setText("1010");
} else {
temperature.setText("1010");
}
}
} catch (Exception e){
}
}
});
calculate.start();
This doesn't work. Also I'm not sure if I'm actually supposed to use a Thread or not. Here's what happens when I enter three variables (The R variable is a constant):
In this case the Temperature text should've changed to "1010".
Here's my isCalcable class:
public class Calculations {
public static boolean isCalcable (String pressure, String volume, String moles, String temperature){
int hasNumber = 0;
if (pressure.length() > 0){
hasNumber++;
}
if (volume.length() > 0){
hasNumber++;
}
if (moles.length() > 0){
hasNumber++;
}
if (temperature.length() > 0){
hasNumber++;
}
if (hasNumber == 3){
return true;
}
return false;
}
}
What do I do?