0

I am trying to create a method in BlueJ called,

toRadians();

The point of this method is to take a any number below 360 and change it into radians. Here is the method code.

public void toRadians(double tempDegrees)
{
    Math.toRadians(tempDegrees)
}

The line of code used to call this method:

toRadians(beamAngleHalf); 

When this method is called is doesn't change beamAngleHalf into radians. I know this is very basic. How can this be resolved?

  • The method can't change the value (see http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value) Instead it returns a new value. So you probably want `beamAngleHalf = toRadians(beamAngleHalf);` – dnault Mar 06 '17 at 20:22

1 Answers1

1

There are a lot of things that could be explained here, including: the difference between Objects and primitives in Java, and the difference between pass-by-reference and pass-by-value, but the short answer is that Math.toRadians(tempDegrees) is not changing the value that is passed into it, it is instead returning the value represented in radians.

You instead need to return what is returned by Math.toRadians() in your toRadians() method.

public double toRadians(double tempDegrees)
{
    return Math.toRadians(tempDegrees);
}
rmlan
  • 4,387
  • 2
  • 21
  • 28