Frank Ventura

Greenhorn
+ Follow
since Nov 05, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Frank Ventura

Actually, the code that is given by the school text book is this

public class SphereVolumeCalculator {
  public static void main (String [] args) {
     double piVal = 3.14159;
     double sphereVolume = 0.0;
     double sphereRadius = 0.0;

     sphereRadius = 1.0;

/* Your solution goes here  */

     System.out.println("Sphere volume: " + sphereVolume);
     return;
  }
}

All I have to do is to add my statement in the page where it reads /* Your solution goes here */.  So most of the text is provided I just need to insert my statement that will make the code work.
This is what I have sphereVolume = sphereRadius * (4.0 / 3.0) * piVal;.  but the code fails.

This is the result I get
 Testing with radius 1.0
Your value: 4.188786666666666
 Testing with radius 0.0
Your value: 0.0
✖   Testing with radius 5.5
Expected value: 696.9093816666666
Your value: 23.038326666666666
3 years ago
Good afteroon,

My name is Frank and I just starting working a Java class... I wanted to know if anyone can help me with the following problem which I'm currently stuck with.

"Given sphereRadius and piVal, compute the volume of a sphere and assign to sphereVolume. Use (4.0 / 3.0) to perform floating-point division, instead of (4 / 3) which performs integer division.  Volume of sphere = (4.0 / 3.0) π r3"

Here is my code, but whatever I do I can't seems to get this working.

import java.util.Scanner;

public class SphereVolumeCalculator {
  public static void main (String [] args) {
     double piVal = 3.14159;
     double sphereVolume = 0.0;
     double sphereRadius = 0.0;

     sphereRadius = 1.0;

     sphereVolume = sphereRadius * ( 4.0 / 3.0) * piVal;

     System.out.println("Sphere volume: " + sphereVolume);
     return;
  }
}
3 years ago