ICSE Class 10 Computer Applications
Question 4 of 6
Solved 2018 Question Paper ICSE Class 10 Computer Applications — Question 4
Back to all questions 4
Question Question 7
Design a class to overload a function volume() as follows:
double volume (double R) – with radius (R) as an argument, returns the volume of sphere using the formula.
V = 4/3 x 22/7 x R3double volume (double H, double R) – with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula.
V = 22/7 x R2 x Hdouble volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula.
V = L x B x H
public class KboatVolume
{
double volume(double r) {
return (4 / 3.0) * (22 / 7.0) * r * r * r;
}
double volume(double h, double r) {
return (22 / 7.0) * r * r * h;
}
double volume(double l, double b, double h) {
return l * b * h;
}
public static void main(String args[]) {
KboatVolume obj = new KboatVolume();
System.out.println("Sphere Volume = " +
obj.volume(6));
System.out.println("Cylinder Volume = " +
obj.volume(5, 3.5));
System.out.println("Cuboid Volume = " +
obj.volume(7.5, 3.5, 2));
}
}