Assignment (itp)
Assignment (itp)
Section&Grade: BSIT – 1E
2.Overloading Exercise
public class Volume {
// Method to calculate the volume of a sphere
public static double volume(double radius) {
return (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
}
// Overloaded method to calculate the volume of a rectangular prism
public static double volume(double length, double width, double height) {
return length * width * height; // V = l * w * h
}
public static void main(String[] args) {
double sphereVolume = volume(3.0);
System.out.println("The Volume of sphere is: " + sphereVolume);
double prismVolume = volume(2, 3, 4);
System.out.println("The Volume of rectangular prism is: " + prismVolume);
}
}
INTERMEDIETE TO PROGRAMMING
OUTPUT CODE: