i am coding a project that has "Shape" as the parent with various shapes (ie rectangle, triangle, etc.) as sub-classes using inheritance. i am supposed "Modify the constructor and set methods of the Shape class to verify the values of X and Y stay between zero and the MAX size. If X or Y are out of range, issue an error message on the console and set the value to zero." for some reason i cannot get it to work. when i run the program it will display the x-value even if it is out of range instead of zero. Here is the code for the parent class "Shape":
public abstract class Shape {
int x;
int y;
protected final static int X_MAX_SIZE=800;
protected final static int Y_MAX_SIZE=600;
//Constructor w/out parameters
public Shape(){
}
//Constructor w/ parameters
public void Shape(int x, int y){
x=getX();
if(x<0 || x>X_MAX_SIZE){
System.out.println("ERROR!");
this.x=0;
} else this.x=x;
y=getY();
}
public int getX(){
return x;
}
public void setX(int x){
if(x<0 || x>X_MAX_SIZE){
System.out.println("ERROR!");
this.x=0;
} else this.x=x;
}
public int getY(){
return y;
}
public void setY(int y){
this.y=y;
}
public abstract double area();
public abstract void display();
public abstract void display(Graphics g);
}