jeudi 29 janvier 2015

Pass values to class


Vote count:

0




I am trying to pass x and y coordinates to a constructor in a class using java.awt.Point. My main class is throwing an error saying "The constructor Quadrilateral(int, int, int, int, int, int, int, int) is undefined. I thought when passing to my constructor 'public Quadrilateral(Point... points)' i could pass the coordinates as a simple list. Can someone tell me where these few lines of code may be going wrong?


Main



import java.awt.Point;


public class QuadrilateralTest
{
public static void main(String[] args)
{
Quadrilateral quadrilateral = new Quadrilateral(1, 1, 6, 2, 6, 9, 2, 7);
System.out.printf("%s %s %s %s %s\n", quadrilateral);
}
}


Quadrilateral class



import java.awt.Point;


public class Quadrilateral
{
//points contain x and y coordinates
private Point point1;
private Point point2;
private Point point3;
private Point point4;


public Quadrilateral(Point... points)
{
point1 = new Point(1, 2);
point2 = new Point(3, 4);
point3 = new Point(5, 6);
point4 = new Point(7, 8);
}

//setters and getters
public Point getPoint1()
{
return point1;
}

public Point getPoint2()
{
return point2;
}

public Point getPoint3()
{
return point3;
}

public Point getPoint4()
{
return point4;
}

public String toString()
{
return ("\nThe Points of the Quadrilateral are:\n " +
getPoint1() +"," + getPoint2() +"," + getPoint3() + "," + getPoint4())+"\n";
}

}


asked 52 secs ago







Pass values to class

Aucun commentaire:

Enregistrer un commentaire