/*
 * File: Test.java
 * Author: Java, Java, Java
 * Description: This program tests the toUpperCase() and
 *   digitToInteger() methods. Note that the methods must be
 *   declared static in order to call them from main().
 */

public class Test {
    public static void main(String argv[]) {
        char ch = 'a';             // Local variables
        int k = (int)'b';

        System.out.println(ch);
        System.out.println(k);
                                // ch = k erroneous assignment
        ch = (char)k;           // so we use an explicit cast
        System.out.println(ch);
        System.out.println(toUpperCase('a'));
        System.out.println(toUpperCase(ch));
        System.out.println(digitToInteger('7'));
    }

    /**
     *  toUpperCase() converts its parameter to uppercase
     *  @param char ch, can be any alphabetic character
     *  @return returns a char in uppercase
     */
    public static char toUpperCase(char ch) {
        if ((ch >= 'a') && (ch <= 'z'))
            return (char)(ch - 32);
        return ch;
    }

    /**
     *  toUpperCase() converts its parameter to an integer. If the
     *   parameter is not a digit, the method returns -1
     *  @param char ch must be a digit -- '0' to '9'
     *  @return returns an int representing the digit's numerical value
     */
    public static int digitToInteger(char ch) {
        if ((ch >= '0') && (ch <= '9'))
            return ch - '0';
        return -1 ;
    }
} // Test
