Can you help me with this code, it's confusing to me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you help me with this code, it's confusing to me

The volume of objects are calculated differently depending on the shape of the object. a) The volume of rectangular prism is calculated using the formula: Create a Volumes application that prompts the user for the length, width, and height of a rectangular prism and then calculates the volume. b) The volume of a sphere is calculated using the formula:

18th Jan 2017, 11:00 PM
Akon
13 Answers
+ 2
I really don't know why, but 'voilà': import java.util.Scanner; public class Volumes { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Rectangular prism size:\nLength?"); double L=sc.nextDouble(); System.out.println("- Width?"); double W=sc.nextDouble(); System.out.println("- Height?"); double H=sc.nextDouble(); System.out.println("Volume = "+rectPrismVol(L,W,H)); System.out.println("Sphere size:\nRadius?"); double R=sc.nextDouble(); System.out.println("Volume = "+sphereVol(R)); } static public double rectPrismVol(double x, double y, double z) { return x*y*z; } static public double sphereVol(double r) { return (4.0/3)*Math.PI*Math.pow(r,3); } } Code in action at: https://code.sololearn.com/cbU1ePs2mFSO/#java
19th Jan 2017, 10:55 PM
visph
visph - avatar
+ 1
And what exactly is confusing you? Do you have any code so far? If not, you might want to start by making two functions, one for calculating the volume of the prism and the other one for the sphere.
18th Jan 2017, 11:27 PM
Robobrine
Robobrine - avatar
+ 1
But you have basic knowledge of the Java syntax and how a program is structured, right?
18th Jan 2017, 11:53 PM
Robobrine
Robobrine - avatar
+ 1
Ok, you should try to get to 'Classes and Objects', because this will teach you how to use functions. Or you can go the lazy rout and just put everything into the main method.
19th Jan 2017, 12:03 AM
Robobrine
Robobrine - avatar
+ 1
But if you learn it now you will be able to write the code yourself in the future. It's really not that hard!
19th Jan 2017, 1:28 AM
Robobrine
Robobrine - avatar
+ 1
@Roborine: "Ok, you should try to get to 'Classes and Objects', because this will teach you how to use functions. Or you can go the lazy rout and just put everything into the main method." @Akon: "I don't have any, its a new topic to me" ... @Akon: "I tried and its just not working" @Roborine: "If you show me your code I can help you figure out what's the problem :D" @Akon: "thats what im saying, i dont have a code yet" Well, you mostly said that you "just need the code"... But you also said have trying and "its" just not working, meaning "the code": so you have at least one, not yet working... Show us, and we'll help you to succeed to make "its" work :P
19th Jan 2017, 7:07 AM
visph
visph - avatar
0
I don't have any, its a new topic to me
18th Jan 2017, 11:37 PM
Akon
0
A little bit I just started this course
18th Jan 2017, 11:58 PM
Akon
0
I tried and its just not working
19th Jan 2017, 3:08 AM
Akon
0
If you show me your code I can help you figure out what's the problem :D
19th Jan 2017, 3:11 AM
Robobrine
Robobrine - avatar
0
thats what im saying, i dont have a code yet
19th Jan 2017, 3:59 AM
Akon
- 1
?? I just need the code
19th Jan 2017, 1:24 AM
Akon
- 1
I don't have it, its gone, I forgot to save it
19th Jan 2017, 10:02 PM
Akon