-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProg2.java
More file actions
107 lines (99 loc) · 2.44 KB
/
Prog2.java
File metadata and controls
107 lines (99 loc) · 2.44 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.Scanner;
class circle
{
double radius;
String color;
circle()
{
radius=1.0;
color="blue";
}
circle(double radius)
{
this.radius=radius;
color="blue";
}
circle(double radius,String color)
{
this.radius=radius;
this.color=color;
}
double getarea()
{
return Math.PI*radius*radius;
}
double getradius()
{
return radius;
}
String getcolor(){return color;}
}
class cylinder extends circle{
double height;
double getheight()
{ return height;
}
cylinder()
{
super();
height=2.0;
}
cylinder(double height)
{
super();
this.height=height;
}
cylinder(double height, double radius)
{
super(radius);
this.height=height;
}
cylinder(double height,double radius, String color)
{
super(radius,color);
this.height=height;
}
double getarea()
{
return ((2* Math.PI*radius*height)+(2* Math.PI*radius*radius));
}
double getvolume()
{
return (super.getarea()*height);
}
void display()
{
System.out.println("\nRadius is "+super.radius+",Height is "+height+", Color is "+super.color+",Area is "+getarea()+",Volume is "+getvolume());
}
void check (cylinder c1,cylinder c2,int i,int j){
if((c1.radius==c2.radius)&& (c1.height==c2.height)&&(c1.color.equalsIgnoreCase(c2.color)))
System.out.println("The cylinders "+(i+1)+" and "+(j+1)+"are similar");
}
}
public class Prog2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
cylinder[] c = new cylinder[4];
int i;
c[0] = new cylinder();
c[1] = new cylinder(3.0);
c[2] = new cylinder(3.0, 4.0, "Green");
System.out.println("Enter the details of cylinder 4 (height , radius and color)");
double h = s.nextDouble();
//s.nextLine();
double r = s.nextDouble();
s.nextLine();
String st = s.nextLine();
c[3] = new cylinder(h, r, st);
for (i = 0; i < 4; i++) {
System.out.println("The dimensions of cylinder " + (i + 1) + " is ");
c[i].display();
}
for (i = 0; i < 4; i++) {
int j;
for (j = i + 1; j < 4; j++) {
c[i].check(c[i], c[j], i, j);
}
}
}
}