0% found this document useful (0 votes)
7 views2 pages

Comp 3

The document contains a Java class named 'volume' that implements method overloading to calculate the volumes of a cube, sphere, and cuboid. It includes methods for each shape that take different parameters and return the respective volumes. The main method prompts the user for dimensions and prints the calculated volumes for each shape.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Comp 3

The document contains a Java class named 'volume' that implements method overloading to calculate the volumes of a cube, sphere, and cuboid. It includes methods for each shape that take different parameters and return the respective volumes. The main method prompts the user for dimensions and prints the calculated volumes for each shape.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Right a class with name volume using method

overloading that computes volume of cube, sphere,


cuboid.

import java.util.*;

public class volume

int c;
public static int volume(int a)
{
return(a*a*a);
}
public static double volume (double r)
{
return(4/3)*3.14*r*r*r;

}
public static double volume(double l,double
b,double h)
{
return(l*b*h);
}
public static void main(String ags[])
{
Scanner sc=new Scanner(System.in);
System.out.println("ENTER SIDE OF CUBE");
int a=sc.nextInt();
System.out.println("ENTER RADIUS OF
SPHERE");
double r=sc.nextDouble();
System.out.println("ENTER LENGTH OF
CUBOID");
double l=sc.nextDouble();
System.out.println("ENTER BREADTH OF
CUBOID");
double b=sc.nextDouble();
System.out.println("ENTER HEIGHT OF
CUBOID");
double h=sc.nextDouble();
System.out.println("volume of cuboid="+
volume(l,b,h));
System.out.println("volume of cube="+
volume(a));
System.out.println("volume of sphere="+
volume(r));

You might also like