Advertisement
NeverRIEght

Pair & ColoredPair

Apr 5th, 2024
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. class Pair {
  2.     private int a;
  3.     private int b;
  4.  
  5.     public Pair(int a, int b) {
  6.         this.a = a;
  7.         this.b = b;
  8.     }
  9.  
  10.     @Override
  11.     public boolean equals(Object obj) {
  12.         boolean result = false;
  13.  
  14.         if(obj.getClass().equals(Pair.class) || obj.getClass().equals(ColoredPair.class)) {
  15.             Pair objPair = (Pair) obj;
  16.             if (this.a == objPair.a && this.b == objPair.b) {
  17.                 result = true;
  18.             } else if (this.a == objPair.b) {
  19.                 result = true;
  20.             } else if (this.b == objPair.a) {
  21.                 result = true;
  22.             }
  23.         }
  24.  
  25.         return result;
  26.     }
  27. }
  28.  
  29. class ColoredPair extends Pair {
  30.     final private String color;
  31.  
  32.     public ColoredPair(int a, int b, String color) {
  33.         super(a, b);
  34.         this.color = color;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement