Question
Project 9-3: Console Tester Create and test interfaces that reduce the Console classs linkage to the presentation layer. Console Welcome to the Console Tester application
Project 9-3: Console Tester
Create and test interfaces that reduce the Console classs linkage to the presentation layer.
Console
Welcome to the Console Tester application
Int Test
Enter an integer between -100 and 100: -150
Error! Number must be greater than -101.
Enter an integer between -100 and 100: 50
Double Test
Enter any number between -100 and 100: 200.75
Error! Number must be less than 101.0.
Enter any number between -100 and 100: 50.75
Required String Test
Enter your email address:
Error! This entry is required. Try again.
Enter your email address: hello@mail.com
String Choice Test
Select one (x/y): z
Error! Entry must be 'x' or 'y'. Try again.
Select one (x/y): x
Specifications
Create an interface named UserOutput that specifies the following methods that display messages to the user:
void print(String s)
void println()
void println(String s)
Create an interface named UserInput that specifies the following methods that get input from the user:
int getInt(String prompt);
int getInt (String prompt, int min, int max);
double getDouble(String prompt);
double getDouble (String prompt, double min, double max);
String getString(String prompt);
String getString(String prompt, String s1, String s2);
Create an interface named UserIO that extends the UserInput and UserOutput interfaces.
Create a class named ConsoleIO that implements the UserIO interface. The constructor for this class should create an instance of the Scanner class that gets input from the standard input stream. The methods for this class should let you get valid input from the user and display output to the user.
Code an IOFactory class that contains a static method named getUserIO that returns an instance of a class that implements the UserIO interface. For this project, return an instance of the ConsoleIO class.
Create a UserIOTestApp class that prompts the user as shown above using a ConsoleIO object from the IO factory. The code in this class shouldnt use the Scanner class or the System.out object directly.
Project 9-3: Console Tester (continued)
Enhancement
Code a class named JOptionPaneIO that implements the UserIO interface. This class should use the showInputDialog() method of the JOptionPane class to get data from the user, and the showMessageDialog method of the JOptionPane class to show data to the user. (Youll have to research this method on your own.)
Edit the getUserIO() method of the IOFactory class so that it accepts a string value and returns either an instance of the ConsoleIO class or the JOptionPaneIO class, depending on the value of the string it receives.
Edit the UserIOTestApp class to get a JOptionPaneIO object from the factory, and then test the application. Then change the code to get a ConsoleIO object and test the application again.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started