Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package test; public class Point { // data fields private double x, y; //Constructor1 public Point(){ x = 0; y = 0; } // Constructor2
package test;
public class Point {
// data fields
private double x, y;
//Constructor1
public Point(){
x = 0;
y = 0;
}
// Constructor2
public Point(double x, double y){
this.x = x;
this.y = y;
}
// Members
// getters
public double getX(){
return x;
}
public double getY(){
return y;
}
// setters
public void setX(double newX){
this.x = newX;
}
public void setY(double newY){
this.y = newY;
}
public void move(double newX, double newY){
this.x = newX;
this.y = newY;
}
public void display(){
System.out.println("(" + this.x + ", " + this.y + ")");
}
public String toString() {
return "("+x+", "+y+")";
}
// driver-method
public static void main(String[] args){
Point p1 = new Point();
Point p2 = new Point(3, 4);
p1.display();
p2.display();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started