Define a class named Point which contains the following memb
Define a class named “Point” which contains the following member variables:
A int called “x”
A int called “y\"
A default constructor A constructor that takes two parameters of type double (which set \"x\" and \"y\", respectively)
Solution
Note:
As you mentioned that the type of instance variables is integer.But at the same time you want to create a parameterized constructor which was taking double type parameters to initialize instance variables.
Both must be same either integer or double.Please check that one.I developed by taking as integer.If you want to modify to double I will do that.Thank You.
__________________
Point.java
public class Point {
//Declaring instance variables
private int x;
private int y;
//Zero argumented constructor
public Point() {
super();
}
//Parameterized constructor
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
//Setters and getters
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public String toString() {
return \"x \" + x + \", y=\" + y ;
}
}
________________
Output:
TestPoint.java
public class TestPoint {
public static void main(String[] args) {
//Displaying the Point class objects by passing the values as arguments
Point p1=new Point(3,4);
//Displaying the contents inside Point Class object
System.out.println(\"Point#1 \"+p1.toString());
Point p2=new Point(6,9);
System.out.println(\"Point#2 \"+p2.toString());
Point p3=new Point(2,6);
System.out.println(\"Point#3 \"+p3.toString());
}
}
___________________
Output:
Point#1 x=3, y=4
Point#2 x=6, y=9
Point#3 x=2, y=6
___________

