Finish Lab10

This commit is contained in:
2022-10-07 21:18:25 -05:00
parent f4bc7fdca4
commit bf56587261
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);