Ask your own question, for FREE!
Computer Science 7 Online
HumzaAli:

Write a program that prompts the user for a bearing from 0 to 359 and prints the corresponding letter of the compass point nearest to the bearing. Bearings exactly halfway between two compass points should produce either N or S (never E or W). The program should loop until the user enters -1, all other values that are not 0 – 359 should produce an error message.

Extrinix:

Found an older post on this: https://questioncove.com/updates/54428f0de4b0e38f7ad1534d

Extrinix:

@Ultrilliam

HumzaAli:

@extrinix are coding?

Extrinix:

It should be something roughly similar to this, given from OpenStudy's original post on it. This will have to be transformed into Java though for your purposes. input bearing # integer in [0 .. 359] case bearing in [315, 45] then print 'N' case bearing in [46, 124] then print 'E' case bearing in [125, 225] then print 'S' case bearing in [226, 314] then print 'W' else print 'ERROR' this is what the code in non java form looks like... but ill convert it to java form

HumzaAli:

how do you convert it into java

HumzaAli:

Are you still here Extrinix

HumzaAli:

^

HumzaAli:

java

SmokeyBrown:

You can use the java class Scanner to read in input from the user. Walkthrough here: https://careerkarma.com/blog/java-input/#:~:text=The%20Scanner%20class%20is%20used%20to%20read%20Java,so%20it%20can%20be%20stored%20or%20otherwise%20manipulated. In order to check the cases as Extrinix described, you'd probably want switch-case statements. Walkthrough here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!