-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleTest4_program03.java
More file actions
71 lines (54 loc) · 2.12 KB
/
Copy pathsampleTest4_program03.java
File metadata and controls
71 lines (54 loc) · 2.12 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
// This code was contributed by https://github.com/voyager2005
import java.util.Scanner;
public class st4_pg3
{
double volume = 0.0;
double volume( double r )
{
// computation
volume = (4.0/3.0) * Math.PI * Math.pow(r,3);
// display statement
System.out.println("Volume of Sphere: " + volume );
return volume;
}
double volume( double r , double h)
{
// computation
volume = (1.0/3.0) * Math.PI * Math.pow(r,2) * h ;
// display statements
System.out.println("Volume of Cone: " + volume );
return volume;
}
double volume( double l, double b, double h)
{
// computation
volume = l * b * h;
// display statement
System.out.println("Volume of Cuboid: " + volume );
return volume;
}
public static void main(String args[])
{
// declaration
Scanner sc = new Scanner(System.in);
st4_pg3 obj = new st4_pg3();
//accpeting the radius from the user
System.out.println("Please enter the raidus of the circle");
double radius = sc.nextDouble();
//calling the overloaded method volume, passing radius in the parameters
obj.volume(radius);
// accpeting the radius and height of the cone from the user
System.out.println("Please enter the radius and the heigth of the cone: ");
double radiusCone = sc.nextDouble();
double heightCone = sc.nextDouble();
//calling the overloaded constructor, passing radius and height of the cone
obj.volume(radiusCone, heightCone);
// accepting the length, bredth and height from the user
System.out.println("Please enter the length, bredth and the height: ");
double lengthCuboid = sc.nextDouble();
double bredthCuboid = sc.nextDouble();
double heightCuboid = sc.nextDouble();
// calling the overloaded constructor volume, passing the length, bredth and the height
obj.volume(lengthCuboid, bredthCuboid, heightCuboid);
}
}