So, I'm making a Snell's Law Calculator with more feautres to it like a Critical Angle Calculator.
And if you know what Snell's Law is, you know you need to have 1 variable. this is the formula: n1*sinθ1 = n2*sinθ2. one of these (n1,θ1,n2,θ2) needs to be a variable. I want to make my program so it doesn't matter which character you put in, it'd count as the variable (eg. X,x,Z,y,l,T....). This is my current code:
if(tbString.contentEquals("x")) {
// If θ2 is a variable - Calculate it.
double taN = Math.toRadians(Double.parseDouble(taString));
double snella = Double.parseDouble(n1String) * Math.sin(taN);
double divA = snella / Double.parseDouble(n2String);
double aSin = Math.asin(divA);
double snellf = Math.toDegrees(aSin);
System.out.println(tbString + " Is equal to: " + snellf);
It's just the calculation to find θ2. (tbString is θ2). Now, I specified saying, if the person writes "x" it'd do the following calculation, Meaning it has to be x, also has to be CaSe SeNsItIvE, And I want it so it'd pick up any letter I put in, Capital or not. I tried looking it up but I couldn't find anything.
Aucun commentaire:
Enregistrer un commentaire