/* This is the triangle/snowflake class for the Kosh Simulation
 */
import java.lang.*;
    
    public class Triangle{
        int n;            //this is the number of permutation
        double length;    //length of origonal side

        // Constructor

        public Triangle(int z, double l){
            n = z;
            length = l;
        }
	
        // calculates permiter by multiplying sidelength and numsides

	public double Permiter(){
            double ans;
            ans = NumSides() * SideLength(n);
            return ans;
	}

        // calculates sidelength for the nth side
        
	public double SideLength(int n){
            double ans;
            ans = length/(Math.pow(3, n-1));
            return ans;
	}

        // calculates the number of sides in the nth permutation

	public int NumSides(){
            int ans = 0;
            ans = (int)(3 * Math.pow(4, n-1));
            return ans;
	}

        // calculates the area of the nth triangle
        
	public double Area(int a){
            double area;
            double height;
            area = Math.pow(SideLength(a),2) * Math.sqrt(3)/4 * NumTriangles(a);
            return area;
	}

        // calculates the number of triangles in the nth permutation
        
        public double NumTriangles(int a){
            double ans = 0;
            if(a == 1){
                ans = 1;
            }else if(a == 2){
                ans = 3;
            }else
            {
                ans = 3 * Math.pow(4, a-2);
            }
                
            return ans;
        }

        // adds all areas up to N
        
        public double TotalArea(){
            double ans = 0;
            for(int i = 1; i <= n; i++){
                ans += Area(i);
            }
            return ans;
        }
    }

