Finish Lab10

This commit is contained in:
2025-10-19 21:30:56 -05:00
parent 227980bc13
commit c069322d36
3 changed files with 58 additions and 18 deletions

View File

@@ -28,16 +28,36 @@ public class CharacterClassStringClass {
userResponse = input.next();
if (userResponse.toLowerCase().charAt(0) == 'y') {
// User has responded with 'y'
System.out.println("You typed '" + userResponse + '\'');
System.out.println("ok!");
if (userResponse.length() > 1) { // User has entered a string that starts with y
// Check if string == yes
if (userResponse.toLowerCase().equals("yes")) {
System.out.println("You typed '" + userResponse + '\'');
System.out.println("ok!");
} else {
System.out.println("Invalid input! You entered '" + userResponse + '\'');
}
} else {
// User has responded with 'y'
System.out.println("You typed '" + userResponse + '\'');
System.out.println("ok!");
}
} else if (userResponse.toLowerCase().charAt(0) == 'n') {
// User has responded with 'n'
System.out.println("You typed " + userResponse.charAt(0));
// Kill the loop.
loopToggle = false;
} // Invalid input handling
else {
if (userResponse.length() > 1) { // User has entered a string that starts with y
// Check if string == yes
if (userResponse.toLowerCase().equals("no")) {
System.out.println("You typed '" + userResponse + '\'');
// Kill the loop.
loopToggle = false;
} else {
System.out.println("Invalid input! You entered '" + userResponse + '\'');
}
} else {
// User has responded with 'n'
System.out.println("You typed " + userResponse.charAt(0));
// Kill the loop.
loopToggle = false;
}
} else { // Invalid input handling
// Attempt to parse string as an integer.
try {
parseCheck = Integer.parseInt(userResponse);