// Aaron Tan
// BallV3 class:
//   Data members: colour, radius, x- and y-coord of centre.
// 
// Version 3: (i) include 'this'
//            (ii) overloaded constructors
//            (iii) toString()
//            (iv) equals()

class BallV3 {

   /************** Data members **********************/

   private String colour;
   private double radius;
   private int    xCoord;  // x- and y-coordinates of
   private int    yCoord;  // the centre of the ball

   /************** Constructors **********************/
   // Default constructor creates a yellow, radius 10.0,
   // centre at (20,20) object.

   public BallV3() {
      this("yellow", 10.0, 20, 20);
   }

   public BallV3(String colour, double radius, int x, int y) {
      setColour(colour);
      setRadius(radius);
      setCentre(x,y);
   }

   /**************** Accessors ***********************/

   public String getColour() {
      return colour;
   }

   public double getRadius() {
      return radius;
   }

   public int getXCoord() {
      return xCoord;
   }

   public int getYCoord() {
      return yCoord;
   }

   /**************** Mutators ************************/
   // illustrates the use of 'this'

   public void setColour(String colour) {
      this.colour = colour;
   }

   public void setRadius(double radius) {
      this.radius = radius;
   }

   public void setCentre(int xCoord, int yCoord) {
      this.xCoord = xCoord;
      this.yCoord = yCoord;
   }

   /***************** Other methods ******************/

   public void moveVertical(int dist) {
      yCoord += dist; // or: setCentre(getXCoord(), getYCoord() + dist);
   }

   public void moveHorizontal(int dist) {
      xCoord += dist; // or: setCentre(getXCoord() + dist, getYCoord());
   }

   /***************** Overriding methods ******************/
  
   // Overriding toString() method
   public String toString() {
      return "[" + getColour() + ", " + getRadius() + ", (" + getXCoord() 
             + ", " + getYCoord() + ")]";
   }

   // This is not an overriding method
   /*
   public boolean equals(BallV3 ball) {
      return this.getColour().equals(ball.getColour()) &&
             this.getRadius() == ball.getRadius() &&
             this.getXCoord() == ball.getXCoord() &&
             this.getYCoord() == ball.getYCoord();
   }
   */

   // This is an overriding equals() method
   public boolean equals(Object obj) {
      if (obj instanceof BallV3) {
          BallV3 ball = (BallV3) obj;
          return this.getColour().equals(ball.getColour()) &&
                 this.getRadius() == ball.getRadius() &&
                 this.getXCoord() == ball.getXCoord() &&
                 this.getYCoord() == ball.getYCoord();
      }
      else
         return false;
   }

}

