# first java exercise

• 03-10-2014, 07:10 PM
first java exercise
This is my first java exercise. i got peace of code and i need to write two methods (Length and IsParallel). my question is how can i check line's length for example if the methode doesnt take any variable in its decleration?

this is the code i got:

Code:

```class Point2D {           private double x;           private double y;           Point2D(double xVal, double yVal)           {                   x = xVal;                   y = yVal;           }           double getX()           {                   return x;           }           double getY()           {                   return y;           }           void details()           {                   System.out.println("("+x+","+y+")");           } } class Line2D {           Point2D first;           Point2D second;           Line2D(Point2D p1, Point2D p2)           {                   first = p1;                   second = p2;           }           void details()           {                   System.out.println("(("+first.getX() + "," + first.getY() + ") , (" +                                                             second.getX() + "," + second.getY() + "))");           }           boolean isParallel(Line2D otherLine)           {                   //add your lines here           }           double length()           {                   //add your lines here           }  } public class LinesTest {           public static void main(String args[])           {                   Line2D line1, line2;                   line1 = new Line2D(new Point2D(10,20), new Point2D(5,15));                   line2 = new Line2D(new Point2D(4,4), new Point2D(33,22));                   System.out.println("The length of line1 is : " + line1.length());                   System.out.println("The length of line2 is : " + line2.length());                   if(line1.isParallel(line2))                   {                             System.out.println("line1 is parallel to line2");                   }                   else                   {                             System.out.println("line1 is not parallel to line2");                   }           } }```
• 03-10-2014, 07:15 PM
Norm
Re: first java exercise
Quote:

i need to write two methods (Length and IsParallel)
Do you have a description of what those methods are supposed to do? You will need that BEFORE you can write any code.

Quote:

how can i check line's length
The class that the methods are in contain data that can be used by the methods.
• 03-10-2014, 07:23 PM
Re: first java exercise
yes, here is what they supposed to do:
The length method should return the length of the line and the isParallel method should check whether this line is parallel to another line represented by another object.
• 03-10-2014, 07:35 PM
Norm
Re: first java exercise
Do you know where the data is that can be used to do that?
Given the data, you will need some formulas to do the computation.
Ask an internet Search engine for those formulas.
• 03-10-2014, 07:43 PM