/*
 * CheckAmount.java
 * sample solution of HW#2
 */

//package pic20a;

import java.io.*;


public class CheckAmount {

    static final String[] singles = {"ONE", "TWO", "THREE", "FOUR", "FIVE",
	    "SIX", "SEVEN", "EIGHT", "NINE"};
    static final String[] teens = {"TEN", "ELEVEN", "TWELVE", "THIRTEEN",
	    "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN",
	    "NINETEEN"}; 
    static final String[] tenth = {"TWENTY", "THIRTY", "FOURTY", "FIFTY",
	    "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};

    public static void main(String[] args) {
	BufferedReader jIn =
		new BufferedReader(new InputStreamReader(System.in));
	String input, amount;
	double amountNum;
	int amountInt, amountFrac;
	int j, k;

	while (true) {

	    System.out.println("->\n-> Please enter check amount " +
		    "(type \"quit\" to exit): ");
	    System.out.print("-> ");

	    try {
		input = jIn.readLine(); 

		if (input == null) {
		    continue;
		} else {
		    input = input.trim();
		}

		if (input.equalsIgnoreCase("quit")) {
		    break;
		}

		amountNum = Double.parseDouble(input);

		if ((amountNum <= 0) || (amountNum >= 1000)) {
		    throw new IllegalArgumentException("out of bounds!" +
		    " Amount should be a positive number less then 1000.");
		}

		amountInt = (int) Math.floor(amountNum);
		amountFrac = (int) (100 * (amountNum - amountInt) + 0.5);

		if (amountFrac == 100) {
		    amountInt++;
		    amountFrac = 0;
		}

		amount = "-> ";

		if (amountInt == 0) {
		    amount += "ZERO";
		} else {

		    if ((j = amountInt / 100) > 0) {
			amount += singles[j - 1] + " HUNDRED ";
			amountInt %= 100;
		    }

		    j = amountInt / 10;
		    k = amountInt % 10;

		    if (j == 1){
			amount += teens[k];
		    } else {
			if (j > 1) {
			    amount += tenth[j - 2] + " ";
			}
			if (k > 0) {
			    amount += singles[k - 1];
			}
		    }

		}

		amount += (" and " + amountFrac + "/100 Dollars");

		System.out.println(amount);

	    } catch (NumberFormatException e) {
		System.out.println("-> ERROR: You must enter a number!");
	    } catch (IllegalArgumentException e) {
		System.out.println("-> ERROR: " + e.getMessage());
	    } catch (Exception e) {
		System.out.println("-> ERROR: Something is wrong!");
	    }

	}
    }
}
