-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace BufferedReader with Keyboard utility for input hand…
…ling in DFAController and Menu
- Loading branch information
Showing
3 changed files
with
80 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package computability.controller; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
|
||
public class Keyboard { | ||
|
||
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
public static String readString() { | ||
try { | ||
return reader.readLine(); | ||
} catch (Exception e) { | ||
System.err.println("Error reading string: " + e.getMessage()); | ||
return ""; | ||
} | ||
} | ||
|
||
public static int readInt() { | ||
try { | ||
return Integer.parseInt(readString()); | ||
} catch (NumberFormatException e) { | ||
System.err.println("Error parsing integer: " + e.getMessage()); | ||
return 0; | ||
} | ||
} | ||
|
||
public static double readDouble() { | ||
try { | ||
return Double.parseDouble(readString()); | ||
} catch (NumberFormatException e) { | ||
System.err.println("Error parsing double: " + e.getMessage()); | ||
return 0.0; | ||
} | ||
} | ||
|
||
public static char readChar() { | ||
String input = readString(); | ||
if (input.length() > 0) { | ||
return input.charAt(0); | ||
} else { | ||
System.err.println("Error reading char: input is empty"); | ||
return '\0'; | ||
} | ||
} | ||
|
||
public static boolean readBoolean() { | ||
try { | ||
return Boolean.parseBoolean(readString()); | ||
} catch (Exception e) { | ||
System.err.println("Error parsing boolean: " + e.getMessage()); | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters