Marc Tone wrote: 1. I'm stuck on the return statement on the 3rd line.
2. Similarly the lines utilizing "charCodeAt", as I keep getting error "Cannot invoke charCodeAt(int) on the primitive type char"
3. Also on the second to last line, I keep getting the error "Cannot invoke padLZ(int) on the primitive type int".
Stephan van Hulst wrote:Hi Marc, welcome to CodeRanch!
OsGridRef seems like a good candidate for for class. prototype is an object that is used as, well, the prototype of any newly created instances of OsGridRef. In Java, this is not necessary, because the class itself defines what instances look like.
Now, you can give the class OsGridRef a method toString(int digits) that also uses member fields easting and northing (e and n are derived from these fields, and don't have to be passed as method parameters).
Instead of doing all this work with floating point values, I would suggest using BigDecimal, because it already works with Strings under the hood (making calculations more exact), and will help in rounding the result to a specific precision.
l1+'A' yields a double value in Java, NOT a String. If you want to perform String concatenation, you'll probably want to use l1+"A" instead, and then the charAt() method.
I think it's a very bad idea to name the variables l1 and l2, because they're easily confused with the integer literals 11 and 12.
Also, you defined e and n as primitives, and then you're calling a method padLZ() on them? That's not how primitives work.