Question: Develop a simple Java GUI, including two JTextFields and one JButton. The first text field is for name input and the second is for age

Develop a simple Java GUI, including two JTextFields and one JButton. The first text field is for name input and the second is for age input. There is a separate Utility class that equips two methods checkName() and checkAge() to verify name and age, respectively. The following criteria must hold.

  • The name cannot be zero character or longer than 15 characters. A character can be either a space, a dash -, an alphabet, or a ,. No other characters or digits are allowed; otherwise, a name exception is thrown to the output or command prompt window.
  • The age must be between 0 and 100 inclusively; otherwise, an age exception is thrown in a similar manner.
  • An exception object e should be caught in a try/catch clause and printed using System.out.println(e) command.
  • The System.out.println(e) for name exception will show one of the following three exception messages. The priority is based on the listed sequence.
    • NameException: 0 <= (30) characters <= 15 is invalid. Note that the number 30 depends on the actual user input.
    • NameException: a special character exists.
    • NameException: a digit exists.
  • The System.out.println(e) for age exception will show an out-of-bound error message like AgeException: 0<= (155) <= 100 is invalid. The value 155 depends on the actual user input.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!