Advertisement
ryguy030286

HW3 Equals Method Update

Feb 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1.     public boolean equals(Shape otherObject) {
  2.          
  3.         // ensure not null
  4.         if (otherObject == null) {
  5.             return false;
  6.         }
  7.      
  8.         // check identity
  9.         if (this == otherObject) {
  10.             return true;
  11.         }
  12.      
  13.         // @todo: check if other object is the same type, return false if not
  14.        
  15.         if (this.getType().equals(otherObject.getType())) {
  16.             return true;
  17.            
  18.         }else return false;
  19.    
  20.  
  21.         // @todo: check area, return false if not equal
  22.  
  23.         if (this.getArea() == otherObject.getArea()) {
  24.             return true;
  25.         }
  26.        
  27.         // @todo: if you want to confirm dimensions are equal, need branch based on shape type first
  28.         // as different _types_ of shapes have different dimensions, but this is depending on if you want
  29.         // to decide that length != width, such that a rectangle of w=5, l=8 is unequal to l=5, w=8
  30.        
  31.        
  32.        if (this.getType().equals("Circle") && (this.getRadius() == (otherObject.getRadius()))) {
  33.            
  34.           return true;
  35.        }
  36.            
  37.            
  38.            
  39.        
  40.      
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement