4 Replies Latest reply: Mar 29, 2008 6:12 PM by 807591

I hava problem with method boolean

The following method boolean controls if the Point is in the rectangle,which is correct...
but the next method, which should show minimal rectangle, if the point is in it,shows an error..
X cannot be resolved
Y cannot be resolved

I tried r.istPunktEnthalten(),but the same ...

public boolean istPunktEnthalten(int X,int Y){
if (X>=x1 && X<=x2 && Y>=y1 && Y<=y2 ){
return true;
}

return false;
}

Rechteck vereinigung(Rechteck r){
if (istPunktEnthalten(X,Y)){
r.x2=X;
r.y2=Y;

return r;
}
else return null;

}

Edited by: baddalgazi on Mar 29, 2008 1:57 PM
• 1. Re: I hava problem with method boolean
Whereas the method "istPunktEnthalten" has the arguments X and Y, they are known in the method, this appears not to be the case with the method "vereinigung" which only has a "Rechteck r" as an argument.

Has that "Rechteck" (German for rectangle) got variables to store the vertices?
• 2. Re: I hava problem with method boolean
of course....
here is the full class rectangle...
I think i understand the problem, but i dont't know how to solve it

public class Rechteck {

int x1,x2,y1,y2;

public Rechteck(int x1, int y1, int x2, int y2){

this.x1=x1;
this.x2=x2;
this.y1=y1;
this.y2=y2;
}

public void bewegeUm(int x,int y){
x1=x1+x;
x2=x2+x;
y1=y1+y;
y2=y2+y;

}

public boolean istPunktEnthalten(int X,int Y){
if (X>=x1 && X<=x2 && Y>=y1 && Y<=y2 ){
return true;

}
return false;
}

Rechteck vereinigung(Rechteck r){
if (istPunktEnthalten(X,Y)){
r.x2=X;
r.y2=Y;

return r;
}

}

//Rechteck ueberlappung(Rechteck r){

public String toString(){

return "["+x1+","+y1+";"+x2+","+y2+"]";
}
}
Edited by: baddalgazi on Mar 29, 2008 3:29 PM
• 3. Re: I hava problem with method boolean
Rechteck vereinigung(Rechteck r){
if (istPunktEnthalten(r.x1,r.y1) && istPunktEnthalten(r.x2,r.y2)){
return this;
}
if (r.istPunktEnthalten(x1,y1) && r.istPunktEnthalten(x2,y2)){
return r;
}
Rechteck ret = new Rechteck ();