I am making a java calculator to find out the density and viscosity of aqueous sucrose solutions (chemistry stuff) and decided to go farther with it. I used Micheal Flanagan's Java library for Sucrose which is the:
import flanagan.physprop.Sucrose;
in the code. I wanted a way to continue entering equations without having to continue pressing run over and over so I created
public static void restart() {
System.out.println("would you like to calculate another solution?(y/n)");
String yn = new String(input.nextLine());
String y = "y";
String n = "n";
System.out.println(yn);
if (yn == y){
tf = true;
}
else {
if (yn == n) {
tf = false;
}
else {
System.out.println("ERROR: Please print 'y' or 'n'");
restart();
}
}
if (tf == true) {
calc();
}
if (tf == false) {
fin();
}
}
I am using a scanner called 'import' which is defined in an earlier line.
static Scanner input = new Scanner(System.in);
So, anyway, what is happening is the code is not restarting, but instead triggering the error. I have tried fixing it by defining the readout as a string and making variables for "y" and "n". I am thinking that "yn" is not registering properly as a string, and cannot think of anything else.
flanagan.jar can be found here.