Created
December 1, 2011 21:17
-
-
Save jackfranklin/1419947 to your computer and use it in GitHub Desktop.
Java Help for Josh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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