Commit c3ef4fc2 authored by 刘家荣's avatar 刘家荣 💬
Browse files

feat(重载Site的加减&数乘)

parent 1388bd7a
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -13,8 +13,23 @@ public class Site extends GridPoint{
        this.plate = plate;
    }
    
    @Override
    public Site subtract(GridPoint rhs){
        return new Site(this.plate, this.getY() - rhs.getY(), this.getX() - rhs.getX());
    }
    
    @Override
    public Site add(GridPoint rhs){
        return new Site(this.plate, this.getY() + rhs.getY(), this.getX() + rhs.getX());
    }
    
    @Override
    public Site multiply(int k){
        return new Site(this.plate, k * this.getY(), k * this.getX());
    }

    @Override
    public String toString() {
        return String.format("GridPoint{Plate: %s, y: %d, x: %d}", this.plate.name(), this.y, this.x);
        return String.format("Site{Plate: %s, y: %d, x: %d}", this.plate.name(), this.y, this.x);
    }
}