Click to See Complete Forum and Search --> : Help for New programmer


ryan449
October 7th, 2009, 03:40 PM
Hello, I am in first year computer science at university... i have an assignment that has one question on it that i cant get my head around and was hoping someone could help me out with it...im sure its very simple...

Precise angle measurements (and geographical coordinates) are often
expressed in the DMS format showing degrees, minutes and seconds (for
example, 234˚12’17”). There are 360 degrees in a circle, there are 60
minutes in one degree and 60 seconds in one minute. Write a program
that inputs angle measurements for two angles (each measurement
requires you to input 3 values) and then adds the two angles together and
prints out the resulting angle. For example,

234˚12’17” + 10˚10’10” = 244˚22’27” (correction in yellow)

Notice that if the sum of the two seconds components exceeds 60 it
“wraps around” (like a clock) but also causes a carry into the minutes of
the result. For example,

10˚20’40” + 10˚20’40” = 20˚41’20”

This wrap around and carry can occur for minutes too (causing a carry into
degrees). The wrap around can also happen for degrees but there’s no
carry in this case. Consider this example:

200˚30’40” + 159˚29’20” = 0˚0’0”

HINT: The integer division and remainder operators are key here. Use
temporary variables to capture each of the carry values. If you have programmed before, please resist the temptation to use an “if” statement -
it’s not needed.

Thanks.

ryan449
October 7th, 2009, 03:41 PM
That (correction in yellow) shouldn't be there!

dlorde
October 7th, 2009, 04:57 PM
What have you got so far, and what exactly is the problem you have with this assignment?

Whenever there is a hard job to be done I assign it to a lazy man; he is sure to find an easy way of doing it...
W. Chrysler

ryan449
October 7th, 2009, 05:03 PM
all i have so far are the inputs of all te angles, im just completly lost with this, everything we have done has been basic multipliation division... i dont no how to go about the math

STLDude
October 7th, 2009, 05:44 PM
Can you do the same math with pen and paper?

ryan449
October 7th, 2009, 06:42 PM
I have an idea on how to do it on paper, but not 100%

ProgramThis
October 8th, 2009, 08:01 AM
I have an idea on how to do it on paper, but not 100%
If you can't do it on paper (meaning you don't completely understand the math) how do you expect to do it in a program? I don't say that to be rude, but you need to understand the problem before you can code up a solution. Start with understanding the problem.

dlorde
October 8th, 2009, 08:10 AM
I have an idea on how to do it on paper, but not 100%
Well you need to sort out exactly how to solve the problem on paper before thinking about Java code.

It basically looks like arithmetic in base 60 and base 360.

Like primary school addition, start with the smallest orders and work up. Start with seconds, move to minutes, adding any carry-over, then degrees, adding any carry-over. So if the seconds or minutes exceed 59, subtract 60 and carry 1 over to the next column. If the degrees exceed 359, just subtract 360.

In Java, you can either use the '-' (subtraction) operator to subtract 60 or 360, or the '%' (modulus) operator to find the remainder after dividing by 60 or 360. The results, in this case, will be the same.

From a programmer's point of view, the user is a peripheral that types when you issue a read request...
P. Williams