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

    I hava problem with method boolean

    807591
      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
          807591
          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
            807591
            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
              807591
                   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 ();
                              // your code comes here
                              return ret;
                   }
              • 4. Re: I hava problem with method boolean
                807591
                its not that complicated..
                i only want to ask in my method vereingen, if the method istPunktEnthalten returns true...thats all...

                if it returns true, that means if istPunktEnthalten()==true

                but there is something not ok...



                Nevertheless thanks for all