Comp 25.05
Comp 25.05
Class- X SMK
Prog. 1 Write a class with the name volume using function overloading that
computes the volume of a cube, a sphere and a cuboid.
Volume of a cuboid(vcd)=l*b*h
//To find the volume of a cube, sphere and cuboid using function overloading
import java.util.*;
public class Compute
{
double vc=0.0D,vs=0.0D,vcd=0.0D;
void volume(int s)
{
vc=s*s*s//Calculates area of a cube
System.out.println(“The volume of a cube=”+vc);
}
void volume(float r)
{
vs=4/3*22/7*r*r*r;//Calculates area of a sphere
System.out.println(“The volume of a sphere=”+vs);
}
void volume(int l, int b, int h)
{
vcd=l*b*h;//Calculates area of a cuboid
System.out.println(“The volume of a cuboid=”+vcd);
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int s,l,b,h;
float r;
System.out.println(“Enter the value of side of a cube, radius of sphere, sides of a
cuboid”);
s=in.nextInt();
r=in,nextFloat();
l=in.nextInt();
b=in.nextInt();
h=in.nextInt();
Compute o=new Compute();
ob.volume(s);
ob.volume(r);
ob.volume(l,b,h);
}
}
VARIABLE LIST