invert if and factor out splat message

This commit is contained in:
jason
2022-01-04 22:07:32 -08:00
parent eba6c07fd0
commit 8a992b6ba4

View File

@@ -59,7 +59,15 @@ public class Splat {
System.out.printf("%10.2f %f\n", i, D); System.out.printf("%10.2f %f\n", i, D);
} }
if (!splat) { if (splat) {
if (terminalReached) {
System.out.printf("%.2f SPLAT\n", (V / A) + ((jump.getAltitude() - (V * V / (2 * A))) / V));
} else {
System.out.printf("%.2f SPLAT\n", Math.sqrt(2 * jump.getAltitude() / A));
}
showRandomSplatMessage();
} else {
System.out.println("CHUTE OPEN"); System.out.println("CHUTE OPEN");
int J = 0; int J = 0;
@@ -115,13 +123,39 @@ public class Splat {
} }
}
boolean chosen = false;
while (!chosen) {
System.out.print("DO YOU WANT TO PLAY AGAIN ");
String Z = scanner.next();
if (Z.equals("YES")) {
break;
}
if (Z.equals("NO")) {
System.out.print("PLEASE ");
while (true) {
Z = scanner.next();
if (Z.equals("YES")) {
chosen = true;
break;
}
if (Z.equals("NO")) {
System.out.println("SSSSSSSSSS.");
return;
}
System.out.print("YES OR NO ");
}
continue;
} else { } else {
if (terminalReached) { System.out.print("YES OR NO ");
System.out.printf("%.2f SPLAT\n", (V / A) + ((jump.getAltitude() - (V * V / (2 * A))) / V)); }
} else { }
System.out.printf("%.2f SPLAT\n", Math.sqrt(2 * jump.getAltitude() / A));
} }
}
private void showRandomSplatMessage() {
switch (random.nextInt(10)) { switch (random.nextInt(10)) {
case 0: case 0:
System.out.println("REQUIESCAT IN PACE."); System.out.println("REQUIESCAT IN PACE.");
@@ -155,36 +189,6 @@ public class Splat {
} }
} }
boolean chosen = false;
while (!chosen) {
System.out.print("DO YOU WANT TO PLAY AGAIN ");
String Z = scanner.next();
if (Z.equals("YES")) {
break;
}
if (Z.equals("NO")) {
System.out.print("PLEASE ");
while (true) {
Z = scanner.next();
if (Z.equals("YES")) {
chosen = true;
break;
}
if (Z.equals("NO")) {
System.out.println("SSSSSSSSSS.");
return;
}
System.out.print("YES OR NO ");
}
continue;
} else {
System.out.print("YES OR NO ");
}
}
}
}
private InitialJumpConditions buildInitialConditions() { private InitialJumpConditions buildInitialConditions() {
System.out.print("\n\n"); System.out.print("\n\n");
@@ -243,6 +247,7 @@ public class Splat {
} }
// Immutable
static class InitialJumpConditions { static class InitialJumpConditions {
private final float originalTerminalVelocity; private final float originalTerminalVelocity;
private final float originalGravitationalAcceleration; private final float originalGravitationalAcceleration;