package lab05;

import java.awt.Color;
import gui.Announcement;

/**
 * An application that shows air quality index (AQI) information in
 * window.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class ShowAQI
{
    /**
     * The entry-point of the application.
     *
     * @param args  The command-line arguments (
     */
    public static void main(String[] args)
    {
        Announcement announcement;
        Color        color;
        int          aqi;
        String       description;

        if ((args == null) || (args.length < 1))
        {
            System.out.println("\nUsage: java ShowAQI aqi\n");
        }
        else
        {
            try
            {
                aqi = Integer.parseInt(args[0]);

                // Set the color and description
                color       = findColor(aqi);
                description = findDescription(aqi);
            }
            catch (NumberFormatException nfe)
            {
                color       = null;
                description = null;
            }

            if ((color == null) || (description == null))
            {
                System.out.println("\nInvalid AQI. Please try again.\n");
            }
            else
            {
                // Construct and show the Announcement
                announcement = new Announcement(description, color);
                announcement.setVisible(true);
            }
        }
    }

    /**
     * Find the Color associated with a particular air quality index (AQI).
     *
     * @param   aqi   The air quality index
     * @return        The associated Color
     */
    private static Color findColor(int aqi)
    {
        return new Color(255, 255, 0);
    }

    /**
     * Find the description associated with a particular category
     *
     * @param   aqi   The air quality index
     * @return        The associated description
     */
    private static String findDescription(int aqi)
    {
        return "Moderate";
    }
}
