-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh10_51_Practice16.java
More file actions
93 lines (73 loc) · 2.08 KB
/
Ch10_51_Practice16.java
File metadata and controls
93 lines (73 loc) · 2.08 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
import java.util.Scanner;
public class Ch10_51_Practice16 {
static class Circle{
Scanner input = new Scanner(System.in);
float radius1;
Circle(){
System.out.print("What will be the radius of Circle: "); this.radius1 = input.nextFloat();
}
public void Area(){
System.out.println("\nArea of Circle: " + (22* this.radius1 * this.radius1)/7);
}
}
static class Cylinder extends Circle{
float radius2;
float height;
Cylinder(){
Scanner input = new Scanner(System.in);
System.out.print("\nWhat will be the radius of Cylinder: "); this.radius2 = input.nextFloat();
System.out.print("What will be the height of Cylinder: "); this.height = input.nextFloat();
}
public void Volume(){
float vol = (22*this.radius2*this.radius2*this.height)/7;
System.out.println("Volume of Cylinder is: " + vol);
}
}
//**************************
static class Rectangle{
double length;
double breadth;
Rectangle(double l , double b){
this.length = l;
this.breadth = b;
}
void getlength(){
System.out.println("Lenght is set to: " + this.length);
}
void getbreadth(){
System.out.println("Breadth is set to: " + this.breadth);
}
void AreaRectangle(){
System.out.println("Area of rectangle: " + this.length*this.breadth);
}
}
static class Cuboid extends Rectangle{
double height;
Cuboid(double l1 , double b1 , double h){
super(l1,b1);
this.height = h;
}
void getheight(){
System.out.println("Height is set to: " + this.height);
}
void Volume(){
System.out.println("Volume of Cuboid: " + this.length*this.breadth*this.height);
}
}
public static void main(String[] args) {
System.out.println();
// Q1. Creating a class circle and inheriting it to Cylinder
Cylinder obj = new Cylinder();
obj.Area();
obj.Volume();
System.out.println();
// Q2. Create a class Rectangle and using inheritance create a class Cuboid
Cuboid obj1 = new Cuboid(12.87,13.78,7.8);
obj1.getlength();
obj1.getbreadth();
obj1.getheight();
System.out.println();
obj1.AreaRectangle();
obj1.Volume();
}
}