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.


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

Results 1 to 3 of 3

Thread: Line2D implementation

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts

    Default Line2D implementation

    Hey guys I got this assignment for my java class, to create two classes Point2D and Line2D.

    Now I've created the Point2D class and it just takes in x,y coordinates and creates a point. It has a few methods, getX, getY and distanceTo(point b)

    What I need to do now is create a Line2D class which also should have a few methods, but I'm stuck at implementing the constructor which should take two point2D variables and create a line between point a and point b.

    So basically the constructor should look like this:

    public Line2D(Point2D a, Point2D b)

    I'm having real trouble getting my head around what should be inside the brackets, so I'm kinda stuck at the moment. Any pointers/help would be greatly appreciated.


  2. #2
    Junior Member
    Join Date
    Feb 2014
    My Mood
    Thanked 0 Times in 0 Posts

    Default Re: Line2D implementation

    Well, this is a constructor method, which is used to initialize class variables. Like;

    private Point2D a;
    private Point2D b;
    public Line2D(Point2D a, Point2D b)
         this.a = a; // This will set passed parameter to class variable a 
         this.b = b; // ^ same
    public double getDistance(){
        // Calculate distance and return it

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 832 Times in 772 Posts
    Blog Entries

    Default Re: Line2D implementation

    @Whitescars, welcome to the forums. Please note the date on threads - this thread is several months old which, in forum and internet time, is an eternity, especially if the original poster has yet to return to the forums since this post. I would also recommend reading The Problem with Spoon-feeding , as a few of your posts could be interpreted as such
    Thread locked

Similar Threads

  1. B-Tree implementation
    By vviston in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 1st, 2013, 08:16 AM
  2. Vector implementation
    By poolman81 in forum Collections and Generics
    Replies: 11
    Last Post: June 3rd, 2012, 06:45 AM
  3. ArrayList implementation
    By meijuh in forum Collections and Generics
    Replies: 8
    Last Post: March 22nd, 2012, 01:03 PM
  4. Interface Implementation
    By Samyx in forum Object Oriented Programming
    Replies: 1
    Last Post: December 2nd, 2009, 03:46 AM
  5. Help wih implementation...
    By Frank_nor in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 24th, 2009, 05:43 PM