First of all, for convenience in working with the console, we'll implement the ConsoleHelper class.
In the future, any work with the console should happen through this class.
Add the following to it:
1) A static BufferedReader field initialized using System.in.
2) A static writeMessage(String message) method that should display
the message string on the console.
3) A static String readString() method that should read a string from
the console. If an exception occurs while reading, display the following message
to the user: "An error occurred while trying to enter text. Try again."
And read the input again. The method should not throw an IOException upward.
Other exceptions should not be handled.
4) A static int readInt() method. It should return the entered number and
use the readString() method. Handle any NumberFormatExceptions inside
the method. If one occurs, then display the following message to the user
"An error while trying to enter a number. Try again." And read in another number.
In this and later tasks, unless specified otherwise, all of a class's fields must
be private and its methods must be public.
- The ConsoleHelper class should create and initialize a private, non-final, static BufferedReader field.
- The ConsoleHelper class should implement a static writeMessage(String message) method that displays a message on the console.
- The ConsoleHelper class should implement a static readString method that returns a string read from the console.
- The ConsoleHelper class should implement a static readInt method that returns a number read from the console.
- The readInt method should use the readString method to read from the console.
- The readString method should catch an IOException, display an error message about incorrect input, and read input from the console again.
- The readInt method should catch a NumberFormatException, display an error message about incorrect input, and read input from the console again.