diff --git a/Assignments/Lab10_CalebFontenot/CharacterClassStringClass.html b/Assignments/Lab10_CalebFontenot/CharacterClassStringClass.html index f12c29d..3caba6c 100644 --- a/Assignments/Lab10_CalebFontenot/CharacterClassStringClass.html +++ b/Assignments/Lab10_CalebFontenot/CharacterClassStringClass.html @@ -53,16 +53,36 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w 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); diff --git a/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/CharacterClassStringClass.java b/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/CharacterClassStringClass.java index 20e0901..53765ee 100644 --- a/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/CharacterClassStringClass.java +++ b/Assignments/Lab10_CalebFontenot/src/lab10_calebfontenot/CharacterClassStringClass.java @@ -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); diff --git a/ZIPs/Lab10_CalebFontenot.zip b/ZIPs/Lab10_CalebFontenot.zip index b390255..1a49228 100644 Binary files a/ZIPs/Lab10_CalebFontenot.zip and b/ZIPs/Lab10_CalebFontenot.zip differ