public class Rectangle{
private double x;
private double y;
private double w;
private double h;
public Rectangle(){
System.out.println("Rectangle create default");
this.x = 10;
this.y = 10;
this.w = 70;
this.h = 80;
}
public Rectangle(double x, double y , double w , double h ){
System.out.println("Rectangle create custom");
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
public String toString(){
return "X:"+this.x+ " Y:"+this.y
+ "W:"+this.w+ " H:"+this.h;
}
public double getX(){
return this.x;
}
public double getY(){
return this.y;
}
public double getW(){
return this.w;
}
public double getH(){
return this.h;
}
public void setX(double x){
this.x = x;
}
public void setY(double y){
this.y = y;
}
public void setW(double w){
this.w = w;
}
public void setH(double h){
this.h = h;
}
public Boolean isTouch(Rectangle r1, Rectangle r2){
if(((r1.x < r2.x + r2.w) && (r1.y < r2.y + r2.h))
&& ((r2.x < r1.x + r1.w) && (r2.y < r1.y + r1.h)) ){
return true;
}
return false;
}
}
import java.io.*;
public class Main{
public static void main(String args[]){
int n;
Rectangle pnt1 = new Rectangle();
Rectangle pnt2 = new Rectangle(0, 0, 0, 0);
System.out.println("pnt1 " + pnt1.toString());
System.out.println("pnt2 " + pnt2.toString());
System.out.println(pnt1.isTouch(pnt1, pnt2));
}
}