-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleExample.java
More file actions
40 lines (37 loc) · 1.17 KB
/
Copy pathCircleExample.java
File metadata and controls
40 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* The Circle class models a circle with a radius and color.
*/
public class CircleExample { // Save as "Circle.java"
// Private instance variables
private double radius;
private String color;
// Constructors (overloaded)
/** Constructs a Circle instance with default radius and color */
public CircleExample() { // 1st Constructor (default constructor)
radius = 1.0;
color = "red";
}
/** Constructs a Circle instance with the given radius and default color*/
public CircleExample(double r) { // 2nd Constructor
radius = r;
color = "red";
}
/** Constructs a Circle instance with the given radius and color */
public CircleExample(double r, String c) { // 3rd Constructor
radius = r;
color = c;
}
// Public methods
/** Returns the radius */
public double getRadius() { // getter for radius
return radius;
}
/** Returns the color */
public String getColor() { // getter for color
return color;
}
/** Returns the area of this circle */
public double getArea() {
return radius * radius * Math.PI;
}
}