-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapes.java
More file actions
39 lines (36 loc) · 946 Bytes
/
Shapes.java
File metadata and controls
39 lines (36 loc) · 946 Bytes
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
package com.codewithHarry.shape;
import java.util.Scanner;
class Shape{
double radius;
double height;
void setRadius(double r){
radius=r;
}
void setHeight(double h){
height=h;
}
}
class Rectangle extends Shape{
public double surfaceArea(double radius){
return radius*radius;
}
}
class Cylinder extends Shape{
public double surfaceArea(double radius,double height){
return (2*3.14*radius*height)+(2*3.14*radius*radius);
}
public double volume(double radius,double height){
return (3.14*radius*radius*height);
}
}
public class Shapes{
public static void main(String[] args){
Rectangle r=new Rectangle();
r.setRadius(2.0);
r.surfaceArea(2.0);
Cylinder c=new Cylinder();
c.setRadius(2.0);
c.setHeight(4.0);
c.surfaceArea(2.0,4.0);
}
}