File tree 6 files changed +149
-0
lines changed
44.Chapter_9_Practice_Set
6 files changed +149
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Cylinder {
2
+ private double height ;
3
+ private double radius ;
4
+
5
+ public void setRadius (double r ) {
6
+ this .radius = r ;
7
+ }
8
+ public double getRadius () {
9
+ return radius ;
10
+ }
11
+
12
+ public void setHeight (double h ) {
13
+ this .height = h ;
14
+ }
15
+ public double getHeight () {
16
+ return height ;
17
+ }
18
+ }
19
+
20
+ public class cwh_44_ps_pr_01 {
21
+ public static void main (String args []) {
22
+ Cylinder rad = new Cylinder ();
23
+ Cylinder hgt = new Cylinder ();
24
+
25
+ rad .setRadius (2.5 );
26
+ hgt .setHeight (5 );
27
+
28
+ System .out .println (rad .getRadius ());
29
+ System .out .println (hgt .getHeight ());
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ class Cylinder {
2
+ private double height ;
3
+ private double radius ;
4
+
5
+ public void setRadius (double r ) {
6
+ this .radius = r ;
7
+ }
8
+ public double getRadius () {
9
+ return radius ;
10
+ }
11
+
12
+ public void setHeight (double h ) {
13
+ this .height = h ;
14
+ }
15
+ public double getHeight () {
16
+ return height ;
17
+ }
18
+
19
+ public double surfaceArea () {
20
+ return (2 * Math .PI * radius * radius ) + (2 *Math .PI * radius * height );
21
+ }
22
+ public double volume (){
23
+ return Math .PI * radius * radius * height ;
24
+ }
25
+ }
26
+
27
+ public class cwh_44_ps_pr_02 {
28
+ public static void main (String args []) {
29
+ Cylinder mycylinder = new Cylinder ();
30
+
31
+ mycylinder .setRadius (2.5 );
32
+ mycylinder .setHeight (5 );
33
+
34
+ System .out .println (mycylinder .getRadius ());
35
+ System .out .println (mycylinder .getHeight ());
36
+
37
+ System .out .println (mycylinder .surfaceArea ());
38
+ System .out .println (mycylinder .volume ());
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ class Cylinder {
2
+ private double height ;
3
+ private double radius ;
4
+
5
+ public Cylinder (double radius , double height ) {
6
+ this .radius = radius ;
7
+ this .height = height ;
8
+ }
9
+
10
+ public double surfaceArea () {
11
+ return (2 * Math .PI * radius * radius ) + (2 *Math .PI * radius * height );
12
+ }
13
+ public double volume (){
14
+ return Math .PI * radius * radius * height ;
15
+ }
16
+ }
17
+
18
+ public class cwh_44_ps_pr_03 {
19
+ public static void main (String args []) {
20
+ Cylinder mycylinder = new Cylinder (5 , 9.8 );
21
+ System .out .println (mycylinder .surfaceArea ());
22
+ System .out .println (mycylinder .volume ());
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ class Rectangle {
2
+ private int length ;
3
+ private int breadth ;
4
+
5
+ public Rectangle () {
6
+ length = 5 ;
7
+ breadth = 5 ;
8
+ }
9
+
10
+ public Rectangle (int length , int breadth ) {
11
+ this .length = length ;
12
+ this .breadth = breadth ;
13
+ }
14
+
15
+ public int getLength () {
16
+ return length ;
17
+ }
18
+
19
+ public int getBreadth () {
20
+ return breadth ;
21
+ }
22
+ }
23
+
24
+ public class cwh_44_ps_pr_04 {
25
+ public static void main (String args []) {
26
+ Rectangle rect = new Rectangle (80 , 40 );
27
+ System .out .println (rect .getLength ());
28
+ System .out .println (rect .getBreadth ());
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ class Sphere {
2
+ private double radius ;
3
+
4
+ public void setRadius (double radius ) {
5
+ this .radius = radius ;
6
+ }
7
+ public double getRadius () {
8
+ return radius ;
9
+ }
10
+ public double volume () {
11
+ return (4 * Math .PI * radius * radius * radius ) / 3 ;
12
+ }
13
+ }
14
+
15
+ public class cwh_44_ps_pr_05 {
16
+ public static void main (String args []) {
17
+ Sphere rad = new Sphere ();
18
+
19
+ rad .setRadius (2.5 );
20
+
21
+ System .out .println (rad .getRadius ());
22
+ System .out .println (rad .volume ());
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments