Question: Design and Requirements In order to execute its task the program must compare character values. For instance, a character named symbol is an upper case
Design and Requirements
In order to execute its task the program must compare character values. For instance, a character named symbol is an upper case letter if and only if the boolean expressions A <= symbol and
symbol <= Z both evaluate true. Analogous expressions can be used to check for lower case letters between a and z and for digits between 0 and 9. To see if symbol is the $ or _ character, the relational operator == shall be used.
Declare a String variable title to store the title of the window as shown in Figure 1 below.
Declare a String variable solicitation to store the input solicitation line, see the template in Figure 1.
Input is solicited on a dialog window as shown in Figure 1, follow the template layout including the icon. In the method that creates the window you must not use the String literals
Figure 1
Declare a String variable input and assign input the String value returned by the window
Validate the input: check out if input is null (the result of the Cancel button) or the empty string (OK button applied with no text written in the window). Empty Strings have zero length, thus input is not accepted if either input == null or input length == zero is true. Using the corresponding Java Boolean expression build an if block. Within the block print the message
No input to process
Program exits
to the console and apply the System.exit(0); statement to terminate the program (no else block is needed here).
Declare an int variable index and a char type variable symbol
Assign index 0 and symbol the the first character of input (use the index variable, not the 0 literal).
Declare two String variables named messageOK and messageNot_OK and assign the String values shown on the message dialogs of Figure 2 and Figure 3. Follow the output templates exactly, including the icons.
|
|
|
Figure 2 Figure 3
Apply an if-else structure to display Figure 2 or Figure 3 according to the cases of a correct or a wrong first character in input. Build a single boolean expression to control the if statement. In the JOptionPane method literals are not allowed, use the declared String variables messageOK or messageNot_OK.
In order to check the second character, re-assign index.
Before the check we have to see if there is a second character. Build and if else structure, the if is controlled by the expression input.length()>=2
In the if block re-assign the variables symbol, messageOK and messageNot_OK
Copy the previous if else code into this if block as a nested structure. The boolean expression that controls the nested if( ) must be fitted to the check of the second character (digits are allowed now)
In the else statement of the outer structure print the following message to the console:
There is no second character to check
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
