Since I don't know any programming forum out there, I thought I would just post here:
Basically, what this program does is normalize angles between 0 and 360 that you provide. For example, if you provide 380, then the program normalizes it to 20. If you input -30, then the program normalizes it to 330. I have one problem though. Let's say the input is 360010. How would I go about solving that? I know it should output 10 but I can't figure out how to do this. Here is my current code by the way:
public class Angle {
/**
* Normalizes an angle.
* @param angle an integer angle (may be negative)
* @return the equivalent angle in the range 0 - 359
*/
public int normalize(int angle)
{
int normalizedAngle;
if (angle >= 0 && angle <= 360)
normalizedAngle = angle;
else if (angle < 0)
normalizedAngle = 360 + angle;
else
normalizedAngle = angle - 360;
return normalizedAngle;
}
}
Any help or hints on how to work this out would be greatly appreciated. I'm just so frustrated right now because I've been staring at this for quite a while and haven't figured anything out.
P.S.: Nothing too complicated though. We only learned primitive data types, instance fields, classes and that sorts so that should tell you guys how far we are in the class.
Basically, what this program does is normalize angles between 0 and 360 that you provide. For example, if you provide 380, then the program normalizes it to 20. If you input -30, then the program normalizes it to 330. I have one problem though. Let's say the input is 360010. How would I go about solving that? I know it should output 10 but I can't figure out how to do this. Here is my current code by the way:
public class Angle {
/**
* Normalizes an angle.
* @param angle an integer angle (may be negative)
* @return the equivalent angle in the range 0 - 359
*/
public int normalize(int angle)
{
int normalizedAngle;
if (angle >= 0 && angle <= 360)
normalizedAngle = angle;
else if (angle < 0)
normalizedAngle = 360 + angle;
else
normalizedAngle = angle - 360;
return normalizedAngle;
}
}
Any help or hints on how to work this out would be greatly appreciated. I'm just so frustrated right now because I've been staring at this for quite a while and haven't figured anything out.
P.S.: Nothing too complicated though. We only learned primitive data types, instance fields, classes and that sorts so that should tell you guys how far we are in the class.