-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCircle.java
More file actions
33 lines (31 loc) · 1.49 KB
/
Copy pathTestCircle.java
File metadata and controls
33 lines (31 loc) · 1.49 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
/**
* A Test Driver for the "Circle" class
*/
public class TestCircle { // Save as "TestCircle.java"
public static void main(String[] args) { // Program entry point
// Declare and Construct an instance of the Circle class called c1
CircleExample c1 = new CircleExample(2.0, "blue"); // Use 3rd constructor
System.out.println("The radius is: " + c1.getRadius()); // use dot operator to invoke member methods
//The radius is: 2.0
System.out.println("The color is: " + c1.getColor());
//The color is: blue
System.out.printf("The area is: %.2f%n", c1.getArea());
//The area is: 12.57
// Declare and Construct another instance of the Circle class called c2
CircleExample c2 = new CircleExample(2.0); // Use 2nd constructor
System.out.println("The radius is: " + c2.getRadius());
//The radius is: 2.0
System.out.println("The color is: " + c2.getColor());
//The color is: red
System.out.printf("The area is: %.2f%n", c2.getArea());
//The area is: 12.57
// Declare and Construct yet another instance of the Circle class called c3
CircleExample c3 = new CircleExample(); // Use 1st constructor
System.out.println("The radius is: " + c3.getRadius());
//The radius is: 1.0
System.out.println("The color is: " + c3.getColor());
//The color is: red
System.out.printf("The area is: %.2f%n", c3.getArea());
//The area is: 3.14
}
}