Use [ code=java ] to start your code and [ /code ] to end it (without the spaces ofcourse). You have used [code] to end also, thats why the code section has not been formatted.
Its refreshing to see that some posters pay attention to atleast some of the rules before posting, but we wont give you ready made code, but we'll help you write it yourself.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
Now let us consider your traingle has three vertices
A (x1, y1)
B (x2, y2)
C (x3, y3).
Now if you want to calculate the distance between any two points ex P(x1,y1) and Q (x2, y2) on a plane the formula is:-
Square_Root [(x2-x1)^2 + (y2-y1)^2]
So using that formula you can get the length of all the three sides of the triangle. Next to calculate the Area of the triangle Whose length of sides are a,b and c the formula is :-
Area = Square_Root [s(s-a)(s-b)(s-c)]
where s -> Semiperimeter that is half the perimeter.
I think this is called the Herons Formula or something similar.
Now I have given you the formulae just convert them to your code.
Plus are you sure the code you have pasted is the working code ?? Cause the area of a rectangle is (base (areax) * height(areay)) why do you have "(area * area)" added to it ??? Are you sure about what you are doing here ??
Also your program would fail if the rectangle is not perfectly horizontal that is the base is inclined at some angle with the X-Axis.
I hope this is good enough to get you on the way.
I think you code is currently working cause since the variable area is declared at the class level, it is by default initialized to 0, hence (area * area) would give you just 0, but if this were C++ you would have found it out earlier as it would give you garbage values.
Also another suggestion would be to drop the IM or SMS speech while posting, type the words fully so we do not have to figure out what you are actually trying to say.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
That's because you only declared those variables locally in the calculateperimeter() method and they have no scope in your calculatearea() method.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
I do not know what theheck you have done here, but it seems plain wrong to me.
private void calculateperimeter(){
int perimeterx = VectorA.getX()-VectorB.getX();
int perimetery = VectorB.getY()-VectorC.getY();
int perimeterz = VectorC.getX()-VectorA.getX();
perimeter=Math.sqrt ((perimeterx * perimeterx) + (perimetery * perimetery) + (perimeterz * perimeterz));
}
If your instructor is ignorant enough this time too I guess you will get away with this also. According to me that is completely the wrong way to calculate the perimeter.
I had already given you the formula for calculating the length of the sides of the triangle (Square_Root [(x2-x1)^2 + (y2-y1)^2]) from which you could calculate the perimeter and then the area.
But to me this appears plain wrong it will give you the incorrect perimeter and will also finally give you a wrong answer for the area of your triangle.
BTW if you do not know what a perimeter is, it is supposed to be the length of the shape, so for the triangle it would be the sum of the length of all the three sides, But honestly such things are basic geometry you should know about.
Also a word of advice, do not simply program to get the marks, Soon no one is going to care whether you got 50 on 50 or 49 on 50 for a kiddy assignment, do it to learn and honestly from the way you have done both your assignments your attitude is nowhere near that.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154