Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created December 1, 2011 21:17
Show Gist options
  • Save jackfranklin/1419947 to your computer and use it in GitHub Desktop.
Save jackfranklin/1419947 to your computer and use it in GitHub Desktop.
Java Help for Josh
public class Triangle
{
private float x;
private float y;
private float z;
private float perimeter;
private float s;
private float area;
public Triangle(float a, float b, float c)
{
//set x, y, z to be each side
x = a;
y = b;
z = c;
perimeter = x + y + z;
}
//returns the perimeter
public float getPer() {
return perimeter;
}
public static void main(String[] args)
{
//because we have a constructor that takes 3 inputs & sets up our triangle from there, we can call new Triangle(4,5,6) and it will automatically call our constructor method Triangle(a,b,c) and then return the instance we just created.
Triangle t = new Triangle(4,5,6);
System.out.println("The perimeter is: " + t.getPer());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment