[java] simple compass class

Creamer

Well-known member
#2
Java:
public class Compass {
    // input degress via external static var using setDegrees function
    private float degrees = 0.0f;
    private int direction = 0;

    public void SetDegrees(float degress) {
        direction = (int) (degress / 45);
    }

    public String getDirection() {
        switch (direction) {
        case 0:
            return "north";
        case 1:
            return "northeast";
        case 2:
            return "east";
        case 3:
            return "southeast";
        case 4:
            return "south";
        case 5:
            return "southwest";
        case 6:
            return "west";
        case 7:
            return "northwest";
        default:
            break;
        }
        return "";
    }
}
 
Top