
import java.awt.*;
import javax.swing.*;
import java.text.*;
/**
 * Class IceCreamAssignment - calculates the price of ice cream basedo nthe flavor and the number of scoops
 * 
 * @author Chase Conner
 * @course CSCI 1130-01
 * @date 10-17-15
 * @version JDK 8
 */
public class IceCreamShoppe extends JApplet
{  
    DecimalFormat myFormat = new DecimalFormat (".00"); //adds a hundredths decimal place  
    
    //declares and initializes the flavor strings
    public static final String CHOCOLATE = "Chocolate";
    public static final String COFFEE = "Coffee";
    public static final String VANILLA = "Vanilla"; 

    //initializes the prices of all flavors
    double chocPrice = 1.55;
    double vanPrice = 1.25;
    double coffPrice = 1.75;
    
    double price = vanPrice;
    //initializes theS number of scoops and the price per scoop
    int scoops = 3;
    double scoopPrice = 1.00;
     
    //initializes the total for all the flavors 
    double totalPrice = 10.00;
    
    String flavor, scoopString, formattedPrice; //declares the strings

    //declares the the aliases for the images and the image icon 
    Image img;
    Image img2;
    ImageIcon icon;
    
    /**
     * Called by the browser or applet viewer to inform this JApplet that it
     * has been loaded into the system. It is always called before the first 
     * time that the start method is called.
     */
    public void init()
    {
        img = getImage(getDocumentBase(), "cone.jpg");
        icon = new ImageIcon (img);
     
        
        flavor = (String)JOptionPane.showInputDialog(this, "Chocolate, Vanilla, or Coffee?", 
                                                     "Freeze Queen", JOptionPane.PLAIN_MESSAGE, 
                                                      icon, null, "select a flavor");

        scoopString = (String)JOptionPane.showInputDialog(this,"1, 2 or 3 scoops?",
                                                      "Freeze Queen!", JOptionPane.PLAIN_MESSAGE, 
                                                       icon, null, "enter 1, 2, or 3.");                                            
        scoops = Integer.parseInt(scoopString);//pasre string to intiger    
        
        
       //switches the flavor prices and the number of scoops and then totals the prices up 
       switch(flavor){
           case "Chocolate": case "CHOCOLATE": case "chocolate":
            switch(scoops){
                case 1: totalPrice = chocPrice + scoopPrice; break;
                case 2: totalPrice = chocPrice + scoopPrice*2; break;
                case 3: totalPrice = chocPrice + scoopPrice*3; break;
            }
            break;
           
           case "Vanilla": case "VANILLA": case "vanilla":
            switch(scoops){
                case 1: totalPrice = vanPrice + scoopPrice; break;
                case 2: totalPrice = vanPrice + scoopPrice*2; break;
                case 3: totalPrice = vanPrice + scoopPrice*3; break;
            }
            break;
           
            case "Coffee": case "COFFEE": case "coffee":
            switch(scoops){
                case 1: totalPrice = coffPrice + scoopPrice; break;
                case 2: totalPrice = coffPrice + scoopPrice*2; break;
                case 3: totalPrice = coffPrice + scoopPrice*3; break;
        }
        break;
}
    
}
 
/**
     * Called by the browser or applet viewer to inform this JApplet that it 
     * should start its execution. It is called after the init method and 
     * each time the JApplet is revisited in a Web page. 
     */
  
 public void start()
    {
        // provide any code requred to run each time 
        // web page is visited
    }

    /** 
     * Called by the browser or applet viewer to inform this JApplet that
     * it should stop its execution. It is called when the Web page that
     * contains this JApplet has been replaced by another page, and also
     * just before the JApplet is to be destroyed. 
     */
    public void stop()
    {
        // provide any code that needs to be run when page
        // is replaced by another page or before JApplet is destroyed 
    }

    /**
     * Paint method for applet.
     * 
     * @param  g   the Graphics object for this applet
     */
    public void paint(Graphics g)
    {
        Image img2 = getImage (getDocumentBase(), "winter.jpg"); //retrieves image
        g.drawImage(img2, 0, 0, getWidth(), getHeight(), this); //sizes image to background
        
        formattedPrice = myFormat.format(totalPrice); //formats the total price as two decimal places 
            
        g.setColor(Color.white); //sets color to white
        
        g.setFont(new Font ("Ravie", Font.BOLD, 30)); //changes the font and its style and size 
        
        g.drawString("Freeze Queen", 350, 250); //adds title
        
        g.setFont( new Font("Courier", Font.PLAIN, 20)); //changes the style to PLAIN and shrinks the font to 20
        
        g.drawString("Flavor = " + flavor, 520, 385); //adds the flavor you chose to the receipt
        g.drawString ("Number of Scoops = " + scoops, 520, 355); //adds the number of scoops you chose to the receipt
        
        g.setFont( new Font("Courier", Font.BOLD, 20)); //changes the style to bold 
        g.drawString("Total = \u0024" + formattedPrice, 520, 490); //adds the total 
        
        g.drawRect(500, 325, 320, 100); //draws rectangle around items 
        g.drawRect(500, 460, 230, 50); //draws rectangle around total 
        
        //adds new shades of brown from the color wheel        
        Color darkBrown = new Color(48,24,24);
        Color mediumBrown = new Color(72,24,24);
        Color lightBrown = new Color(120,72,48);
        Color darkTan = new Color(192,144,120);
        Color lightTan = new Color(240,216,192);
        
        //adds new shades of tan form the color wheel 
        Color newBlack = new Color(36,28,25);
        Color tanPink = new Color(208,177,159);
        Color buff = new Color(255,246,239);
        Color beige = new Color(235,215,208);   
            
            //swaps the ice cream' color based on the flavor chosen
       
            switch (flavor){
            case "Chocolate": case "chocolate": case "CHOCOLATE":
                    g.setColor(darkBrown);
                switch(scoops){
                case 1:
                    g.fillOval(220, 468, 150, 150);
                    break;
                case 2:
                    g.fillOval(220, 376, 150, 150);
                    g.fillOval(220, 468, 150, 150);
                    break;
                case 3:
                    g.fillOval(220, 270, 150, 150);
                    g.fillOval(220, 376, 150, 150);
                    g.fillOval(220, 468, 150, 150);
                    break;  
                }
                break;
            case "Vanilla": case "vanilla": case "VANILLA":
                    g. setColor(tanPink);
                    switch(scoops){
                case 1:
                    g.fillOval(220, 468, 150, 150);
                    break;
                case 2:
                    g.fillOval(220, 376, 150, 150);
                    g.fillOval(220, 468, 150, 150);
                    break;
                case 3:
                    g.fillOval(220, 270, 150, 150);
                    g.fillOval(220, 376, 150, 150);
                    g.fillOval(220, 468, 150, 150);
                    break;  
                }
                break;
            case "Coffee": case "coffee": case "COFFEE": 
                    g.setColor(mediumBrown);
                 switch(scoops){
                case 1:
                    g.fillOval(220, 468, 150, 150);
                    break;
                case 2:
                    g.fillOval(220, 376, 150, 150);
                    g.fillOval(220, 468, 150, 150);
                    break;
                case 3:
                    g.fillOval(220, 270, 150, 150);
                    g.fillOval(220, 376, 150, 150);
                    g.fillOval(220, 468, 150, 150);
                    break;  
                }
                break;
        
            }
            
        //draws and fills the cone 
        g.setColor(darkTan);
        int xpoints[] = {200, 390, 300};
        int ypoints[] = {542, 542, 790};
        int npoints = 3;
        g.fillPolygon(xpoints, ypoints, npoints);
}
        
   

    /**
     * Called by the browser or applet viewer to inform this JApplet that it
     * is being reclaimed and that it should destroy any resources that it
     * has allocated. The stop method will always be called before destroy. 
     */
    public void destroy()
    {
        // provide code to be run when JApplet is about to be destroyed.
    }


    /**
     * Returns information about this applet. 
     * An applet should override this method to return a String containing 
     * information about the author, version, and copyright of the JApplet.
     *
     * @return a String representation of information about this JApplet
     */
    public String getAppletInfo()
    {
        // provide information about the applet
        return "Title: IceCreamAssignment  \nAuthor: Chase Conner  \nCalculates the price of ice cream based on the flavor and the number of scoops.";
    }


    /**
     * Returns parameter information about this JApplet. 
     * Returns information about the parameters than are understood by this JApplet.
     * An applet should override this method to return an array of Strings 
     * describing these parameters. 
     * Each element of the array should be a set of three Strings containing 
     * the name, the type, and a description.
     *
     * @return a String[] representation of parameter information about this JApplet
     */
    public String[][] getParameterInfo()
    {
        // provide parameter information about the applet
        String paramInfo[][] = {
                 {"firstParameter",    "1-10",    "description of first parameter"},
                 {"status", "boolean", "description of second parameter"},
                 {"images",   "url",     "description of third parameter"}
        };
        return paramInfo;
    }
}
