shape7: Circle.java

/*
 * Definition of class circle
 */

class Circle extends Shape {

	private int rad;

	// N.B. This shows how you can use same var name in ivar and arg
	public Circle (int x, int y, int rad) { //*1 How to use same var name in ivar and arg
		this.x = x; this.y = y; //*1
		this.rad = rad; //*1
	}

	public void setSize (int rad) { //*1
		this.rad = rad; //*1
	}

	public void draw() {
		System.out.println ("Drawing circle at " + x + ", " + y
			+ ", radius = " + rad);
	}

	public float area() {
		return (float) (rad * rad * 3.14159);
	}
}
[download file]