   import java.io.*;
   import java.util.Scanner;

/**
 * A command-line application that can be used to calculate sales taxes
 * on different kinds of items.
 *
 * This application accepts one command-line argument, containing the
 * name of the output file.  If the command-line argument is omitted,
 * this application will send all output to the console 
 * (i.e., standard output).
 *
 * This work complies with the JMU Honor Code.
 *
 * @author  Jimmy Tessitore
 * @version 1.1 September 15, 2008
 */
    public class TaxOnomy
   {
   	//Declaration of PrintStream
      private static PrintStream    tape;
   	
   	//Declaration and Instantiation of Scanner object
      private static Scanner        keyboard = new Scanner(System.in);
   
    /**
     * The entry point of the application
     *
     * @param args   The command-line arguments
     */
       public static void main(String[] args)
      {
      	//Declarations
         File           tapeFile;       
         double[]       prices;
         int[]          categories;
         int            numberOfItems;
         String         itemRequestMessage;
      
       
       // Code that handles the command-line arguments
         tape = null;
      
       // If there is a command-line argument, use it as the
       // file name (if possible)
         if ((args != null) && (args.length > 0))
         {
            tapeFile = new File(args[0]);
            try
            {
               tape  = new PrintStream(tapeFile);
            }
                catch (IOException ioe)
               {
                  tape  = System.out;          
               }
         }
         // Otherwise, use System.out
         else
         {
            tape = System.out;          
         }
       
       // The application logic
         numberOfItems = requestInt("Enter the number of items: ");
         System.out.print("You wish to enter " + numberOfItems + " items.\n");    
      
      //Set arrays equal to number of items
         prices = new double[numberOfItems];
         categories = new int[numberOfItems];   	
      	
      	//Fills arrays with values
         for(int i=0; i<numberOfItems; i++)
         {
            categories[i] = requestCategory();
				System.out.print("You entered " + categories[i] + ".\n");
            prices[i] = requestDouble(); 
				System.out.print("You entered " + prices[i] + ".\n");
         }     
      		
      		//Prints results using printf
         System.out.printf("%10s\n %10s %8.4f\n %10s %8.4f\n %10s %8.4f\n",
            "Summary",
            "Food: ", 
            TaxCalculator.foodTax(prices, categories),
            "Prepared: ",
            TaxCalculator.preparedfoodTax(prices, categories),
            "Other: ",
            TaxCalculator.nonfoodTax(prices, categories));							 
      
         //Check to make sure the program ends normally
         System.out.println("\nThis program has ended normally.");
      	
      // Sytem.out.prinf(" 10s% 8.4f%","Four:", 
      }//end main
   
   
    /**
     * Prompt the user to enter a category and then
     * read it in (using the Scanner named keyboard).
     *
     * This method will/must continue to prompt the user
     * until she/he enters a valid category
     *
     * @return         The value 
     */
       private static int requestCategory()
      {
         //Declaration
         int        category;
       
         //Initialization
         category = -1;
      	
      	//Asks for category		 
         System.out.print("Enter 0 for non-food, "
			+ "1 for food, or 2 for prepared: ");
      	//Takes in value entered
         category = keyboard.nextInt();
      
         //Continues to ask until entry is valid
         while(TaxCalculator.isValid(category) == false)
         {
            //Asks for category again
            System.out.print("Enter 0 for non-food, "
               + "1 for food, or 2 for prepared: ");
         	//Takes in value entered
            category = keyboard.nextInt();
         }
         
      	//returns number of category chosen
         return category;
      }
   
   
   
   
    /**
     * Prompt the user to enter a double and then
     * read it in (using the Scanner named keyboard)
     *
     * @return         The value 
     */
       private static double requestDouble()
      {
         //Declaration
         double          value;
         
      	//Initialization
         value = 0.0;
         
      	//Asks for user entry for the price
         System.out.print("Enter the price: ");	
      	//Takes in user entry
         value = keyboard.nextDouble();
      
         //returns value entered
         return value;
      }
   
   
   
    /**
     * Prompt the user to enter an int and then
     * read it in (using the Scanner named keyboard)
     *
     * @param prompt   The custom portion of the prompt
     * @return         The value 
     */
       private static int requestInt(String prompt)
      {
         //Declaration
         int          value;
       
         //Initialization
         value = 0;
       
       	//Prints prompt parameter
         System.out.print(prompt);
      	//Takes in value of prompt
         value = keyboard.nextInt();
         
      	//returns value entered
         return value;
      }
   
    
   }//end TaxOnomy
