Results 1 to 3 of 3
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default Trying to create a program with objects

    I am trying to write my first programs where I (kind of) understand objects but it won't compile and I don't know why. It is only a basic program to find the distance between two points.


    Java Code:
    class PointObject{
    import java.awt.Point;
        
        public static void main(String[] args){
            Point coord1 = new Point(1,2);			// Enter the first co-ordinate here
            System.out.println("Co-ordinate 1 is (" + coord1.x + "," + coord1.y + ")");
            Point coord2 = new Point(4,6);			// Enter the first co-ordinate here
            System.out.println("Co-ordinate 2 is (" + coord2.x + "," + coord2.y + ")");
            System.out.println("The distance between the two points is " + pointDist(coord1, coord2));
        }
        
        public static double pointDist(Point firstcoord, Point secondcoord){
        	double dx = secondcoord.x - firstcoord.x;
            double dy = secondcoord.y - firstcoord.y;
            
            double dxSquared = dx * dx;
            double dySquared = dy * dy;
            
            return Math.sqrt(dxSquared + dySquared);
        }
        
    }

  2. #2
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default Re: Trying to create a program with objects

    the code wrapper on this forum has cut of the end of line 9, it does have another ) and a ; on the end of it.

  3. #3
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default Re: Trying to create a program with objects

    I've worked it out, I put the import statement in the wrong place :)

Similar Threads

  1. Create objects. What happens to objects on close
    By rru96 in forum New To Java
    Replies: 1
    Last Post: 10-13-2012, 09:46 AM
  2. Replies: 12
    Last Post: 04-29-2012, 02:55 PM
  3. For loop to create objects
    By SteroidalPsycho in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 09:31 AM
  4. How to create an array of objects
    By redmaverick in forum New To Java
    Replies: 7
    Last Post: 10-19-2009, 02:14 AM
  5. Replies: 1
    Last Post: 01-22-2009, 04:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •