Internally your program should have two Java classes: ValidatorNumeric (superclass) ValidatorString (subclass) The subclass ValidatorString extends ValidatorNumeric class, forming a hierarchy of two classes. Add a separate main class with the main() method to test all public methods in both ValidatorNumeric and ValidatorString classes. The main() method should create the necessary objects and run the user interaction as shown above. The ValidatorNumeric class is responsible for capturing user prompt and a range of valid numeric inputs. Its methods display the prompt and accept input from the user. It should provide the following public interface: // Default constructor ValidatorNumeric() // Specific constructor taking params as follows: ValidatorNumeric( String prompt, int min, int max ) // Another specific constructor taking params as follows: ValidatorNumeric( String prompt, double min, double max ) // Method that shows user prompt and gets an int from the user: public int getInt() // Method that shows user prompt and gets an int within a range. // Consider throwing InvalidArgumentException if min > max. public int getIntWithinRange() // Method that shows user prompt and gets a double from the user: public double getDouble() // Method that shows user prompt and gets a double within a range: // Consider throwing InvalidArgumentException if min > max. public double getDoubleWithinRange() Add private data attributes to store the values String prompt int min int max double min double max Optionally you can also add some getter and setter methods for the data attributes of the ValidatorNumeric class. NOTE: Make sure that all methods of the ValidatorNumeric class are non-static. Create another class named ValidatorString that extends the ValidatorNumeric. It is responsible for displaying user prompt and accepting string inputs from the user. The ValidatorString class should provide the following public interface: // Default constructor: ValidatorString() // Specific constructor taking a user prompt param: ValidatorString( String prompt ) // Specific constructor taking a user prompt and two choice params: ValidatorString( String prompt, String choiceOne, String choiceTwo ) // Method that shows user prompt and returns a non-empty string from the user: public String getRequiredString() // Method that shows user prompt and returns one of the two pre-defined choices. // Consider throwing InvalidArgumentException if any of choiceOne or choiceTwo is empty. public String getChoiceString() Add private data attributes to store the values String prompt String choiceOne String choiceTwo Optionally you can also add some getter and setter methods for the data attributes of the ValidatorString class. NOTE: Make sure that all methods of the ValidatorString class are non-static.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question
  • Internally your program should have two Java classes:

    • ValidatorNumeric (superclass)

    • ValidatorString (subclass)

    The subclass ValidatorString extends ValidatorNumeric class, forming a hierarchy of two classes.

  • Add a separate main class with the main() method to test all public methods in both ValidatorNumeric and ValidatorString classes. The main() method should create the necessary objects and run the user interaction as shown above.


  • The ValidatorNumeric class is responsible for capturing user prompt and a range of valid numeric inputs. Its methods display the prompt and accept input from the user. It should provide the following public interface:

    // Default constructor ValidatorNumeric() // Specific constructor taking params as follows: ValidatorNumeric( String prompt, int min, int max ) // Another specific constructor taking params as follows: ValidatorNumeric( String prompt, double min, double max ) // Method that shows user prompt and gets an int from the user: public int getInt() // Method that shows user prompt and gets an int within a range. // Consider throwing InvalidArgumentException if min > max. public int getIntWithinRange() // Method that shows user prompt and gets a double from the user: public double getDouble() // Method that shows user prompt and gets a double within a range: // Consider throwing InvalidArgumentException if min > max. public double getDoubleWithinRange()
  • Add private data attributes to store the values

    String prompt int min int max double min double max
  • Optionally you can also add some getter and setter methods for the data attributes of the ValidatorNumeric class.

  • NOTE: Make sure that all methods of the ValidatorNumeric class are non-static.

    • Create another class named ValidatorString that extends the ValidatorNumeric. It is responsible for displaying user prompt and accepting string inputs from the user. The ValidatorString class should provide the following public interface:

      // Default constructor: ValidatorString() // Specific constructor taking a user prompt param: ValidatorString( String prompt ) // Specific constructor taking a user prompt and two choice params: ValidatorString( String prompt, String choiceOne, String choiceTwo ) // Method that shows user prompt and returns a non-empty string from the user: public String getRequiredString() // Method that shows user prompt and returns one of the two pre-defined choices. // Consider throwing InvalidArgumentException if any of choiceOne or choiceTwo is empty. public String getChoiceString()
    • Add private data attributes to store the values

      String prompt String choiceOne String choiceTwo
    • Optionally you can also add some getter and setter methods for the data attributes of the ValidatorString class.

    • NOTE: Make sure that all methods of the ValidatorString class are non-static.

 

Create an object-oriented application that validates user input. In particular, the application
should prompt the user to
o Enter a valid integer within a specified range
o Enter a valid double within a specified range
o Enter a required string
o Display two strings and ask user to enter one of them
If any of the above user responses aren't valid, the program should display a descriptive error
message and repeat the prompt for the correct value. For example,
Welcome to the Validation Tester application
Int Test
Enter an integer between -100 and 100: x
Error! Invalid integer value. Try again.
Enter an integer between -100 and 100: -101
Error! Number must be greater than -101
Enter an integer between -100 and 100: 101
Error! Number must be less than 101
Enter an integer between -100 and 100: 100
Double Test
Enter any number between -100 and 100: x
Error! Invalid decimal value. Try again.
Enter any number between -100 and 100: -101
Error! Number must be greater than -101.0
Enter any number between -100 and 100: 101
Error! Number must be less than 101.0
Enter any number between -100 and 100: 100
Required String Test:
Error! This entry is required. Try again.
Required String Test: THIS IS A TEST
You entered: THIS IS A TEST
String Choice Test
Select one (x/y):
Error! This entry is required. Try again.
Select one (x/y): q
Error! Entry must be 'x' or 'y'. Try again.
Select one (x/y): x
All done!
Transcribed Image Text:Create an object-oriented application that validates user input. In particular, the application should prompt the user to o Enter a valid integer within a specified range o Enter a valid double within a specified range o Enter a required string o Display two strings and ask user to enter one of them If any of the above user responses aren't valid, the program should display a descriptive error message and repeat the prompt for the correct value. For example, Welcome to the Validation Tester application Int Test Enter an integer between -100 and 100: x Error! Invalid integer value. Try again. Enter an integer between -100 and 100: -101 Error! Number must be greater than -101 Enter an integer between -100 and 100: 101 Error! Number must be less than 101 Enter an integer between -100 and 100: 100 Double Test Enter any number between -100 and 100: x Error! Invalid decimal value. Try again. Enter any number between -100 and 100: -101 Error! Number must be greater than -101.0 Enter any number between -100 and 100: 101 Error! Number must be less than 101.0 Enter any number between -100 and 100: 100 Required String Test: Error! This entry is required. Try again. Required String Test: THIS IS A TEST You entered: THIS IS A TEST String Choice Test Select one (x/y): Error! This entry is required. Try again. Select one (x/y): q Error! Entry must be 'x' or 'y'. Try again. Select one (x/y): x All done!
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT