20120211

Portfolio

MATLAB Graphical User Interface (GUI): Projectile Motion

MATLAB is yet another application and programming language I've added to my skill set this year. In this post I'm going to share with you a program I wrote in MATLAB that models projectile motion. It has a convenient little Graphical User Interface (GUI) where the user can input the initial velocity (m/s) and angle (degrees),  and the program will spit out a x-y plot. 

[Download This!]

20120201

Java Project #12: Statistics


/**
 * class Statistics finds the mean and standard deviation of given numbers.
 * 
 * @author (Andrew Samuels) 
 * @version (04-09-2010)
 */
//import scanner
import java.util.Scanner;

public class Statistics
{
    
    public static void main(String[] args)
    {
        //create variables
        int size;
        int i;
        
        //create scanner
        Scanner keyboard = new Scanner(System.in);
        
        //capture size from user
        System.out.print("How many numbers will be entered: ");
        size = keyboard.nextInt();
        
        //create array of "size"
        double[] p = new double[size];
        
        //read numbers from user one by one
        for(i = 0; i < size; i ++)
        {
            System.out.print("Enter number " + (i + 1) +": ");
            p[i] = keyboard.nextDouble();
        }
        
        //find mean
        double sum = 0;
        for(i = 0; i < size; i++)
        {
            sum = sum + p[i];
        }
        
        double mean = sum/(double)size;
        System.out.println("Mean: " + mean);
        
        //find standard deviation
        double temp = 0;
        for (i = 0; i < size; i++)
        {
            temp = temp + (p[i] - mean)*(p[i] - mean);
        }
        temp = Math.sqrt(temp/size);
        
        System.out.println("Standard deviation: "+ temp);
    }
}

Java Project #11: Array Work

This script shows off various array operations.


/**
 * class ArrayWork.
 * 
 * @author (Andrew Samuels) 
 * @version (04-05-2010)
 */
//import scanner
import java.util.Scanner;

public class ArrayWork
{
    
    public static void main(String[] args)
    {
        //create variables
        int length;
        int i;
        int zeros;
        
        //create scanner
        Scanner keyboard = new Scanner(System.in);
        
        //capture length from user
        System.out.print("Enter the length of array: ");
        length = keyboard.nextInt();
        
        int[] p = new int[length]; //creates array of length, "length"
        System.out.println();
        
        //read integers one by one
        for(i = 0; i < length; i ++)
        {
            System.out.print("Enter number " + (i + 1) +": ");
            p[i] = keyboard.nextInt();
        }
        
        //print numbers in order user entered them
        System.out.print("Numbers: ");
        System.out.println();
        for(i = 0; i < length; i++)
        {
            System.out.print(p[i] + " ");
        }
        
        
        //find sum and average of of numbers and print them
        int sum = 0;
        for(i = 0; i < length; i++)
        {
            sum = sum + p[i];
        }
        System.out.println();
        System.out.println("Sum: " + sum);
        System.out.println();
        
        double average = sum/(double)length;
        System.out.println("Average: " + average);
        System.out.println();
        
        //find max and min in array and print
        int maximum = p[0];
        for (i = 0; i < length; i++)
        {
            if (p[i] > maximum)
            {
                maximum = p[i];
            }
        }
        System.out.println("Maximum: " + maximum);
        System.out.println();
        
        int minimum = p[0];
        for (i = 0; i < length; i++)
        {
            if (p[i] < minimum)
            {
                minimum = p[i];
            }
        }
        System.out.println("Minimum: " + minimum);
        System.out.println();
        
        //print all positive numbers
        
        System.out.println("Positives: ");
        for (i = 0; i < length; i++)
        {
            if (p[i] > 0)
            {
                System.out.print(p[i]+" ");
            }
        }
        
        //find and print zeros
        zeros = countZeros(p);
        System.out.println("Zeros: " + zeros);
        
        //reverse array and print
        printReverse(p);
        
        
    }
    
    //count zeros method
    private static int countZeros(int[] array)
    {
        int answer = 0;
        int i;
        for(i = 0; i < array.length; i++)
        {
            if(array[i] == 0)
            {
                answer = answer + 1;
            }
         
        }
        return answer;
    }
    
    //print reverse method
    private static void printReverse(int[] array)
    {
        int i;
        for(i = array.length - 1; i >= 0; i--)
        {
            System.out.print(array[i] + " ");
        }
        
    }
   
    //display method
    public static void display(int[] array)
    {
        for(int i = 0; i < array.length; i++)
        {
            System.out.println(array[i]);
        }
    }
}

Java Project #10: Area Finder


/**
 * class AreaFinder compute area of square, rectangle, circle.
 * 
 * @author (Andrew Samuels) 
 * @version (03-29-2010)
 */
public class AreaFinder
{
    private static final double pi = 3.1415; //value of constant pi
    private static int count = 0; //count of times area computed
    
    //computes area of square
    public static double squareArea(double sideOfSquare)
    {
        double areaOfSquare = sideOfSquare * sideOfSquare;
        count++;
        return areaOfSquare;
        
    }
    
    //computes area of rectangle
    public static double rectangleArea(double width, double height)
    {
        double areaOfRectangle = width * height;
        count++;
        return areaOfRectangle;
        
    }
    
    //computes area of circle
    public static double circleArea(double radius)
    {
        double areaOfCircle = pi * radius * radius;
        count++;
        return areaOfCircle;
        
    }
    
    //returns number of times the area computing methods were called
    public static int getCallCount()
    {
        return count;
    }
}