-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircle.java
More file actions
54 lines (50 loc) · 1.31 KB
/
Copy pathCircle.java
File metadata and controls
54 lines (50 loc) · 1.31 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
// Writen by Edgar Colin
// Aug 12th 2016
// Class: CIS163 Java I
// Prof: Michael Parmeley
// Section 14887
// HW 4 Problem 6(a)
// Filename: TestCircle.java
Create a class named Circle with fields named radius,
diameter, and area. Include a constructor that sets
the radius to 1 and calculates the other two values.
Also include methods named setRadius()and getRadius()
The setRadius() method not only sets the radius
but also calculates the other two values. (The
diameter of a circle is twice the radius,
and the area of a circle is pi multiplied by the
square of the radius. Use the Math class PI
constant for this calculation.) Save the class as
Circle.java.
*/
import java.util.*;
import static java.lang.Math.*;
public class Circle
{
private double radius;
private double diameter;
private double area;
public Circle()
{
radius = 1;
diameter = 2*radius;
area = Math.PI*radius*radius;
}
public void setRadius(double rad)
{
radius = rad;
diameter = 2*radius;
area = Math.PI*radius*radius;
}
public double getRadius()
{
return radius;
}
public void display()
{
System.out.println("Radius :" + radius);
System.out.println("Diameter :" + diameter);
System.out.println("Area :" + area);
}
}