1 public class CircleWithException {
2
3 private double radius;
4
5
6 private static int numberOfObjects = 0;
7
8
9 public CircleWithException() {
10 this(1.0);
11 }
12
13
14 public CircleWithException(double newRadius) {
15 setRadius(newRadius);
16 numberOfObjects++;
17 }
18
19
20 public double getRadius() {
21 return radius;
22 }
23
24
25 public void setRadius(double newRadius)
26 throws IllegalArgumentException {
27 if (newRadius >= 0)
28 radius = newRadius;
29 else
30 throw new IllegalArgumentException(
31 "Radius cannot be negative");
32 }
33
34
35 public static int getNumberOfObjects() {
36 return numberOfObjects;
37 }
38
39
40 public double findArea() {
41 return radius * radius * 3.14159;
42 }
43 }