/*
 * PrintNumbers.java
 * Version 1.0 
 */
package com.fiddle.printnumbers;

import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * This program prints the numbers from 1 to X. But for multiples of 2 print
 * "Fiddle" instead of the number and for multiples of 5 print "Faddle" instead
 * of the number. For numbers which are multiples of both 2 and 5 print
 * "Fiddle Faddle" instead of the number.
 * 
 * The program has been constructed in jdk1.7.0_60 The program should prompt for
 * and accept user input for X from the commandline The program should do basic
 * input validation on what the user enters (e.g. -1 and X are invalid input)
 * The program should exit when the user enters 'quit'
 * 
 * @author Brij Sharma
 * 
 */
public class PrintNumbers {

	private static final String INVALID_INPUT = "Invalid input '";
	private static final String ENTER_AN_INTEGER_0 = "Enter an integer > 0:";
	private static final String FIDDLE_FADDLE = "Fiddle Faddle";
	private static final String FADDLE = "Faddle";
	private static final String FIDDLE = "Fiddle";
	private static Scanner scanner = new Scanner(new InputStreamReader(System.in));
	private static String input = null;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {

			while (true) {

				System.out.print(ENTER_AN_INTEGER_0);
				input = scanner.nextLine();

				if (input.equalsIgnoreCase("quit")) {
					Runtime.getRuntime().exit(0);
				}

				int inputValue = 0;

				if (isInteger(input)) {
					inputValue = Integer.parseInt(input);
				} else {
					System.out.println(INVALID_INPUT + input + "'");
					continue;
				}

				if (inputValue < 1) {
					System.out.print(INVALID_INPUT + inputValue + "'\n");
					continue;
				}

				int[] array = new int[inputValue];

				for (int i = 0; i < array.length; i++) {
					array[i] = i + 1;

				}

				printOutput(array);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * @param array
	 */
	private static void printOutput(int[] array) {
		for (int i : array) {

			if (i == 1) {
				System.out.println(i);
			} else if (i % 2 == 0 && i % 5 == 0) {
				System.out.println(FIDDLE_FADDLE);
			} else if (i % 2 == 0) {
				System.out.println(FIDDLE);
			} else if (i % 5 == 0) {
				System.out.println(FADDLE);
			} else {
				System.out.println(i);
			}

		}
	}

	/**
	 * @param input
	 * @return
	 */
	public static boolean isInteger(String input) {
		try {
			Integer.parseInt(input);
		} catch (NumberFormatException e) {
			return false;
		}
		return true;
	}

}
