// ClassifyChar4.java
// Classifies the characters in an
// entered string of 1 to 15 characters,
// using logical operators.
// Uses dialog box I/O.

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class ClassifyChar4  {
   public static void main(String[] args)
   {
      String text = JOptionPane.showInputDialog(
                       "Enter any string of 1 to 15 characters:");

      while ( text.length() == 0 || text.length() > 15 )
         text = JOptionPane.showInputDialog(
                       "Your string must be 1 to 15 characters:");

      JTextArea output = new JTextArea(20, 30);

      output.append("Position\tCharacter\tClassification\n\n");

      for ( int i = 0; i < text.length(); i++ )  {

         // Display character's position in String text:
         output.append(i + "\t");

         // Display the character itself:
         char x = text.charAt(i);
         output.append(x + "\t");

         // Classify the character:
         if ( x > 127 )
            output.append("non-ASCII character\n");
         else if ( x == ' ' )
            output.append("ASCII space\n");
         else if ( x >= '0' && x <= '9' )
            output.append("ASCII digit\n");
         else if ( (x >= 'A' && x <= 'Z')
                  || (x >= 'a' && x <= 'z') )
            output.append("ASCII letter\n");
         else if ( x < 32 || x == 127 )
            output.append("ASCII control character\n");
         else
            output.append("ASCII punctuation mark\n");
      }  // for i

      JOptionPane.showMessageDialog(null, output);

      System.exit(0);
   }  // method main
}  // class ClassifyChar4