// Michael Thomas and others

/* Useful imports */

import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.codec.*;
import edu.neu.ccs.console.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.parser.*;
import edu.neu.ccs.pedagogy.*;
import edu.neu.ccs.quick.*;
import edu.neu.ccs.util.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.beans.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.regex.*;
import java.text.ParseException;

/** The sample starter class for Java Power Framework. */
public class FHS_Methods_01 extends JPF 
{
    
    public static void main(String[] args) { 
    	new FHS_Methods_01().window.installSimpleMouseActions(true);
    }
    
    
    public void Costa_AreaTriangle()
    {
        double x, y, z;
            
        while(true)
        {
            console.out.println("This will compute the area of a triangle. " +
                                "Press 0 to escape");
            
            x = console.in.demandDouble("Enter the height.");
            if(x==0)
            {
                console.out.println("\nDone.\n");
                break;
            }
            else
            {
            y = console.in.demandDouble("Enter the length of the side.");
            z = (x*y)/2;            
            console.out.println("\nThe area of the triangle is " + z + "\n\n");
            }
            
        }
    }
    
    
    public void Costa_TaxCalc()
    {
        double cost, rate, total;
        
        while (true)
        {
        cost = console.in.demandDouble("Please enter the price of whatever the hell you are buying (0 to exit):");
        if (cost == 0) break;
        rate = console.in.demandDouble("Please enter the sales tax for your state \n" +
                                       "ex) - for 5%, enter 5:");
        total = cost * (1 + (rate / 100));
        console.out.println("The total cost for this item is $" + total + "\n\n");   
        
        }
        
        console.out.println("\n\nDone");
        
                
    }
    
    
    public void Costa_ShapeMan() 
    {
        window.installSimpleMouseActions(true);
        window.clearSequence();
        
        XRect armL = new XRect(50, 100, 100, 50);
        window.addPaintable(armL);
        
        XRect armR = new XRect(250, 100, 100, 50);
        window.addPaintable(armR);
        
        XRect legL = new XRect(150, 250, 40, 100);
        window.addPaintable(legL);
        
        XRect legR = new XRect(210, 250, 40, 100);
        window.addPaintable(legR);
        
        XRect body = new XRect(150, 100, 100, 150);
        window.addPaintable(body);
        
        XCircle head = new XCircle(200, 50, 50);
        window.addPaintable(head);
        
        window.repaint();
    }
    
    

    //  calculate the factorial of a number between 0 and 20
    public void Janulawicz_FactorialFinder() {
        long ntemp = 1;
        long n = 1;

        while(ntemp != 0) {

        console.out.println("Enter an integer to calculate n! or 0 to stop.\n");

        n = console.in.demandLong("Enter n:");

        ntemp = n;

        if((n > 0) && (n <= 20)) {
            long answer = n;
    
             while(n > 1){
                 n--;
                 answer *= n;
             }
    
             console.out.println(ntemp + "! = " + answer + "\n");
        } 

        if(n == 0) console.out.println("Bye!");

        if((n < 0) || (n > 20)) 
            console.out.println("Sorry, this function only works for numbers greater than 0 and less than 21\n"); 
        }
    }
    

    public void Kiopres_Array() {
        // in finalGrades[]= {95, 87, 93, 84, 79};
        
        int[] finalGrades = {95, 87, 93, 84, 79};
        
        for (int i = 0; i < 5; i++)
        {
            System.out.println
            ("Student " + i + "'s final grade was: " + finalGrades[i]);
        }
    }
    
    
    public void Leinung_MakeTakeapartBaseballPlayer () {
        window.clearSequence();
        
        XRect b = new XRect(175,125,50,150);
        window.addPaintable(b);
        
        XLine2D gc = new XLine2D(135,150,250,50);
        window.addPaintable(gc);
        
        XCircle h = new XCircle(190,85,40);
        ShapePaintable sp =
            new ShapePaintable(h, PaintMode.FILL_DRAW, Colors.violet);
        window.addPaintable(sp);
        //XLine2D (x,y,x1,y1)
        XLine2D a1 = new XLine2D(135,150,200,175);
        window.addPaintable(a1);
        
        XLine2D a2 = new XLine2D(135,150,175,175);
        window.addPaintable(a2);
        
        XLine2D L2 = new XLine2D(205,275,215,385);
        window.addPaintable(L2);
        
        XLine2D L1 = new XLine2D(185,275,165,385);
        window.addPaintable(L1);
        
        window.repaint();
        
    }
    
    
    public void Leinung_TakeApart () {
        window.clearSequence();
        
        XRect b = new XRect(123,200,50,150);
        window.addPaintable(b);
        
        XLine2D gc = new XLine2D(35,240,150,140);
        window.addPaintable(gc);
        
        XCircle h = new XCircle(278,300,40);
        ShapePaintable sp =
            new ShapePaintable(h, PaintMode.FILL_DRAW, Colors.violet);
        window.addPaintable(sp);
        //XLine2D (x,y,x1,y1)
        XLine2D a1 = new XLine2D(100,40,165,65);
        window.addPaintable(a1);
        
        XLine2D a2 = new XLine2D(300,150,335,175);
        window.addPaintable(a2);
        
        XLine2D L2 = new XLine2D(46,275,56,385);
        window.addPaintable(L2);
        
        XLine2D L1 = new XLine2D(220,10,200,120);
        window.addPaintable(L1);
        
        window.repaint();
    }
    
    
    public void McLaughlin_Test() {
        //test arrays
        int[] array1 = {2, 4, 6, 8};
        int[] array2 = new int[10];
        //populates array 2
        for (int i = 0; i<10; i++){
                array2[i] = i;
        }
        
        //tests Homework1.ave
        System.out.println(McLaughlin_ave(array1) + " should be 5.0.");
        System.out.println(McLaughlin_ave(array2) + " should be 4.5.");
    }
    
    
    /**
     * McLaughlin
     * 
     * Adds all terms of the array of integers and returns that value.
     * 
     * @param a     integer array to be summed
     * @return      sum of the array of ints
     */
    public static float McLaughlin_sum(int[] a) {
        float sm = 0;
        for (int i = 0; i<a.length; i++){
                sm = sm + a[i];
        }
        return sm;
    }
    
    
    /**
     * McLaughlin
     * 
     * Takes the given array of integers and calculates the average.
     * 
     * @param terms array of integers to average
     * @return              average of the array of integers
     */
    public static float McLaughlin_ave(int[] terms) {
        float av = 0;
        av = McLaughlin_sum(terms)/terms.length;
        return av;
    }
    
    
    public void Morgano_CalculatePowerOfTwo() {
        double answer = 1;
              
        console.out.println("Enter power of 2 to calculate\n");
              
        
        double power = console.in.demandDouble("Enter positive exponent:");
                  
        if(power == 0)
          console.out.println("2^" + power + " = 1" + "\n");
         
        else{
          while(power > 0){
            answer = answer * 2;
            power--;
          }
          console.out.println("2^" + power + " = " + answer + "\n");
       }
      }
    
    
    public void Olejarz_1() {
        int x = 1;
        int counter = 0;
        int y = 264;
        
        for (x = 1; x <= y; x++) {
            counter += (x * 2 - 1);
        }
        
        System.out.println ("the total1 is " + counter);
        
        counter /= y;
        
        System.out.println ("the total2 is " + counter);
    }
    
    
    public void Olejarz_2() {
        int x = 1;
        int counter = 0;
        int y = 264;
        
        for (x = 1; x <= 5; x++) {
            counter += x * (Math.pow(2, x-1));
            System.out.println ("the total is " + counter);
            
            x += 1;
        }
        
        System.out.println ("the final total is " + counter);
    }
    
    
    public void Olejarz_3() {
        int x = 1;
        int counter = 0;
        int y = 264;
        
        for (x = 1; x < 79; x++) {
            counter += x;
        }
        
        System.out.println ("the final total is " + counter);
    }
    
    
    public void Pelc_FirstCode() {
        Pelc_FirstCode.main(null);
    }
    
    
    public void Reed_Average() {
        // A program that find the average of 5 numbers 
        // and prints it to the screen
                        
        int a = 87;
        int b = 94;
        int c = 72;
        int d = 82;
        int e = 75;
        
        int average = ((a + b + c + d + e) / 5);
        
        System.out.println ("The Average is: " + average);
        
        //for some reason I have to hit run twice to get the message 
        //to stay on the screen, and I can't figure out why
    }
    
    
    public void Sawyer_Person() {
        window.clearSequence();
        
        XCircle s = new XCircle(200,75,50);
        window.addPaintable(s);
        
        XLine2D m = new XLine2D(200,125,200,300);
        window.addPaintable(m);
        
        XLine2D n = new XLine2D(200,175,125,125);
        window.addPaintable(n);
        
        XLine2D o = new XLine2D(200,175,275,125);
        window.addPaintable(o);
        
        XLine2D p = new XLine2D(200,300,250,375);
        window.addPaintable(p);
        
        XLine2D q = new XLine2D(200,300,150,375);
        window.addPaintable(q);
        
        window.repaint();
    }
    
    
    public void Scullane_RectAndCirc() {
        
        XRect x = new XRect (50,32,300,150);
        window.addPaintable(x);
        
        XCircle y = new XCircle (400,300,100);
        window.addPaintable(y);
        
        XRect a = new XRect (150,340,400,450);
        window.addPaintable(a);
        
        XCircle b = new XCircle (50,50,5);
        window.addPaintable(b);
        
        window.repaint();
    }

    
    public void Thomas_Show_Hide()
    {
    	this.toggleConsole();
    	this.toggleGraphics();
    }
    
    
    public void Thomas_ListSearcher() {
        new Thomas_ListSearcher();
    }
    
}
