Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4) E5.9 A compass needle points a given number of degrees away from North, measu

ID: 3870691 • Letter: 4

Question

4) E5.9 A compass needle points a given number of degrees away from North, measured clockwise. Write a program that reads the angle and prints out the nearest compass direction; one of N, NE, E, SE, S, SW, W, NW. In the case of a tie, prefer the nearest principal direction (N, E, S, or W). 4) E5.9 A compass needle points a given number of degrees away from North, measured clockwise. Write a program that reads the angle and prints out the nearest compass direction; one of N, NE, E, SE, S, SW, W, NW. In the case of a tie, prefer the nearest principal direction (N, E, S, or W). 4) E5.9 A compass needle points a given number of degrees away from North, measured clockwise. Write a program that reads the angle and prints out the nearest compass direction; one of N, NE, E, SE, S, SW, W, NW. In the case of a tie, prefer the nearest principal direction (N, E, S, or W).

Explanation / Answer

class direction

{

    float a = 1/8f;

    int i = 0;

    float c;

    public direction( String str )

    {

        if( str.contains( "W" ) )

        {

            i = 4;

        }

        switch( str.length() )

        {

            case 1:

                print( Angl1( str ) );

            case 2:

                print( Angl2( str ) );

            case 3:

                if( str.contains( "b" ) )

                {

                    Angl34( str , 1 );

                }

                Angl3( str );

        }

        Angl34( str , 2 );

    }

    int getValue( char x )

    {      

        switch( x )

        {          

            case 'N':

                return n;

            case 'E':

                return 1;

            case 'S':

                return 2;          

        }

        return 3;

    }

    int Angl1( String str )

    {

        return getValue( str.charAt( 0 ) );

    }

    float Angl2( String str )

    {

        return (( getValue( str.charAt( 0 ) ) + getValue( str.charAt( 1 ) ) ) / 2f) ;

    }

   void Angl34( String str , int n )

    {

        if( n < 2 ) c = getValue( str.charAt( 0 ) );

        else c = Angl2( str.substring( 0 , n ) );

        if( getValue( str.charAt( 1 + n ) ) < c )

        {

            a = -a;

        }

        print( c + a );

    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote