-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstract_Class(Geometry).java
82 lines (81 loc) · 2.29 KB
/
Abstract_Class(Geometry).java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Read Description for question//
import java.util.*;
abstract class GeometricObject{
private String color;
private boolean filled;
public GeometricObject(){
color="White";
filled=false;
}
public GeometricObject(String s,boolean b){
color=s;
filled=b;
}
public boolean isFilled(){
return filled;
}
public String getColor(){
return color;
}
public void setColor(String s){
color=s;
}
public void setFilled(boolean b){
filled=b;
}
public abstract double getArea();
public abstract double getPerimeter();
}
class Circle extends GeometricObject{
private double radius;
public Circle(){
radius=1.0;
}
public Circle(double d){
radius=d;
}
public Circle(double d,String s, boolean f){
super(s,f);
radius=d;
}
public void setRadius(double d){
radius=d;
}
public double getArea(){
return Math.PI*radius*radius;
}
public double getPerimeter(){
return 2*Math.PI*radius;
}
public void printCircle(){
System.out.println("Radius:"+radius);
}
}
class Main{
public static void main(String args[]){
Circle c1=new Circle();
c1.setRadius(3.2);
System.out.println("Circle Object 1");
c1.printCircle();
System.out.println("Area:"+c1.getArea());
System.out.println("Perimeter:"+c1.getPerimeter());
System.out.println("Color:"+c1.getColor());
System.out.println("Filled:"+c1.isFilled());
Circle c2=new Circle(2.0);
//c1.setRadius(1.0);
System.out.println("Circle Object 2");
c2.printCircle();
System.out.println("Area:"+c2.getArea());
System.out.println("Perimeter:"+c2.getPerimeter());
System.out.println("Color:"+c2.getColor());
System.out.println("Filled:"+c2.isFilled());
Circle c3=new Circle(3.0,"Black",true);
//c1.setRadius(1.0);
System.out.println("Circle Object 3");
c3.printCircle();
System.out.println("Area:"+c3.getArea());
System.out.println("Perimeter:"+c3.getPerimeter());
System.out.println("Color:"+c3.getColor());
System.out.println("Filled:"+c3.isFilled());
}
}