title: Java beginner: Sphere class
body: <p>I'm looking for help for the code i posted below. It's a problem I have to make a sphere class and another class to test it out. I've pretty much understood everything but the only thing that's killing me is setting a new diameter and getting a new volume. The diameter easily changes when I set a new one, but when I try to run volume again, it just uses the old diameter and not the new one. Please help thank you!</p>
  
  <pre><code>public class Sphere {
  private double sphDiam, volume, surfArea;
  private final double VOL_RELAY = 4.0 / 3.0;
  private final int SURF_CONST = 4;
  
  public Sphere(double sphDiam) {
      this.sphDiam = sphDiam;
      setVolume();
      setSurfaceArea();
  }
  
  public double getDiam() {
      return sphDiam;
  }
  
  public void setDiam(double sphDiam) {
      this.sphDiam = sphDiam;
  }
  
  public double getVolume() {
      return volume;
  }
  
  public void setVolume() {
      volume = Math.pow(sphDiam / 2, 3) * Math.PI * VOL_RELAY;
  }
  
  public double getSurfaceArea() {
      return surfArea;
  }
  
  public void setSurfaceArea() {
      surfArea = Math.pow(sphDiam / 2, 2) * Math.PI * SURF_CONST;
  }
  
  public String toString() {
      return "Sphere diameter: " + sphDiam + "\nSphere Volume: " + volume + "\nSphere Surface Area: " + surfArea; 
  }
  }
  
  public class MultiSphere {
  
  public static void main(String[] args) {
  
      Sphere sph1 = new Sphere(10.5);
      Sphere sph2 = new Sphere(8.4);
      Sphere sph3 = new Sphere(20.1);
  
      sph1.setDiam(3.2);
      System.out.println(sph1.getDiam());
      System.out.println(sph1.getVolume());
      System.out.println(sph1.getSurfaceArea());
      System.out.println(sph1);
      System.out.println();
      sph1.setDiam(2.5);
      System.out.println(sph1.getDiam());
      System.out.println(sph1.getVolume());
      System.out.println(sph1.getSurfaceArea());
      System.out.println(sph1);
      System.out.println();
  
  
      System.out.println(sph2.getDiam());
      System.out.println(sph2.getVolume());
      System.out.println(sph2.getSurfaceArea());
      System.out.println(sph2);
      System.out.println();
  
      System.out.println(sph3.getDiam());
      System.out.println(sph3.getVolume());
      System.out.println(sph3.getSurfaceArea());
      System.out.println(sph3);
      System.out.println();
  }
  }
  </code></pre>