#Help with getting output

1 messages · Page 1 of 1 (latest)

hot pier
#

yo guys
so uh
I need help
im in 9th grade
and like
this is for my dads work
I wrote the code right
I just dont know how to get the output
6) Write a program to define a class overload with the three member function name “volume”-
i) void volume(int s) – to calculate volume of a cube. [Formula of cube: sss]

ii) void volume(int l, int b, int h) – to calculate volume of a cuboid. [Formula of cuboid: lbh]

iii) void volume(double r) – to calculate volume of a sphere. [Formula of sphere: 4 3 ∏𝑟 3 ]

       class Volume {
void volume(int s) {
    System.out.println("Volume of cube: " + (s * s * s));
}

void volume(int l, int b, int h) {
    System.out.println("Volume of cuboid: " + (l * b * h));
}

void volume(double r) {
    System.out.println("Volume of sphere: " + (4.0 / 3.0) * Math.PI * Math.pow(r, 3));
}

}

public class VolumeTest {
public static void main(String[] args) {
Volume v = new Volume();
v.volume(3); // cube
v.volume(3, 4, 5); // cuboid
v.volume(5.0); // sphere
}
}
this is 10th grade stuff
so Im really confused
someone tell me how this works

solar micaBOT
#

<@&987246399047479336> please have a look, thanks.

hot pier
#

idk if I used the right tag 😭

solar micaBOT
#

Please use this format for posting code:

```java
// Example java program
int value = 5;
System.out.println(value);
```

Which results in:

// Example java program
int value = 5;
System.out.println(value);

For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.

hot pier
#

oh

coarse hawk
#

Void means each output returns nothing, so in this case your output is to the console through those print statements.

#

So when you run your main method there will be three output lines.

hot pier
#

I've never done this before in my life

solar micaBOT
coarse hawk
#

I recommend creating your code in there, then you can just run your test class.

hot pier
#

alr

sick rose