Demo entry 6323401

Immutable Class Example

   

Submitted by anonymous on Nov 14, 2016 at 09:17
Language: Java. Code size: 589 Bytes.

public final class Point {
    private final double  x;
    private final double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Point() {
        this.x = 0;
        this.y = 0;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }
    
    public Point translate(double dx, double dy) {
        return new Point(this.x + dx, this.y + dy);
    }
    
    public Point scale(double s) {
       return new Point(this.x * s, this.y * s);
    }
    
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).