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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Perimeter of polygon and area of triangle

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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:
    Last edited by term204; April 15th, 2018 at 08:19 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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).
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    term204 (April 15th, 2018)

  6. #5
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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

  7. #6
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    268
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: Perimeter of polygon and area of triangle

    We need to see more code in order to solve
    Whatever you are, be a good one

Similar Threads

  1. help creating program for area and perimeter of triangle
    By tinker99 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 3rd, 2014, 07:23 AM
  2. [Easy] Finding area of triangle, rectangle, and circle.
    By GMPoison in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 3rd, 2013, 06:21 PM
  3. Replies: 5
    Last Post: August 10th, 2013, 03:21 PM
  4. Diamond perimeter with loop
    By Lanto in forum Loops & Control Statements
    Replies: 5
    Last Post: August 9th, 2012, 12:02 PM
  5. Area of a triangle (using 2 extra methods) error help
    By SilentPirate in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 12th, 2010, 06:08 PM