Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Perimeter of polygon and area of triangle

1. ## Perimeter of polygon and area of triangle

Hello:
Need help to figure out why my code fail to compile in the following functions:

perimeter = perimeter + yc[i].distanceTo(yc[i+1]); //get polygon perimeter

area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2; //get area triangle

here is my code:  Reply With Quote

2. ## Re: Perimeter of polygon and area of triangle

why my code fail to compile
Please copy the full text of the error message and paste it here. It has important info about the error(s).  Reply With Quote

3. ## Re: Perimeter of polygon and area of triangle

Here is the error:

Herencia.java:109: error: array required, but double found
perimeter = perimeter + yc[i].distanceTo(yc[i+1]);
^
Herencia.java:109: error: array required, but double found
perimeter = perimeter + yc[i].distanceTo(yc[i+1]);
^
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable x1
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable y2
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable y3
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable x2
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable y3
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable y1
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable x3
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable y1
location: class Triangulo
Herencia.java:156: error: cannot find symbol
area = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) / 2;
^
symbol: variable y2
location: class Triangulo
11 errors  Reply With Quote

4. ## Re: Perimeter of polygon and area of triangle

Herencia.java:109: error: array required, but double found
perimeter = perimeter + yc[i].distanceTo(yc[i+1]);
^
Primitive variables do not have methods. yc[i] is a double. double is a primitive
What are you trying to do in that statement.

Herencia.java:156: error: cannot find symbol
The compiler can not find a definition for the variable named in those error messages. Make sure the variables are defined in scope where they are being used. In scope means within the same pair of {}s.  Reply With Quote

5. ## The Following 2 Users Say Thank You to Norm For This Useful Post:

term204 (April 15th, 2018)

6. ## Re: Perimeter of polygon and area of triangle

What are you trying to do in that statement.
I do not know the formula to get the perimeter of the polygon.. i found similar code on internet and i try to insert here..

The compiler can not find a definition for the variable named in those error messages. Make sure the variables are defined in scope where they are being used. In scope means within the same pair of {}s.
Thanks  Reply With Quote

7. ## Re: Perimeter of polygon and area of triangle

We need to see more code in order to solve  Reply With Quote