programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# I Was Thinking, Yah, Scary

Rodge Paroissiaux
Greenhorn
Posts: 29
I recently got back into Java (Beginner, very much so) and I was trying to think of a program I could write, but I am not sure how to go about it, since I don't understand how the logic works in labeling.

My initial thought was, what if I start at a point, say, 0, then travel east, north, south, west no more than 3000 steps. Why 3000? No reason, it just popped into my head, so I am going with it. Well, since Java is object oriented, let's just make it squares (say, a chessboard). So, you have Block 0, then you can travel four directions. But how do you label them? My ultimate goal would be to progress the program so that it tells a user to choose a block, then program tells user how many blocks away from 0 it is, not just horizontal-then-vertical, but also diagonal. Then, to make it even more complicated, eventually add a two-point input, then tell the number of blocks away from those, including diagonal distance.

This is where I do not understand the logic. I understand the numbering X, Y, but what about a jump 64 east, then 64 north? Do I label each block the coordinate, or is there some weird math/logic involved in naming it? And aside from the names, what if I do use the coordinates, how would I tell the program what fits the bill for "shortest route"? I can set up the logic to left x-number, down y-number, but will that always be the shortest route? Diagonal will not always be a straight shot, it will likely be three west, one south, three west, one south, until the final point. But even if it keeps that pattern, what if in the last stretch to hit the square, it only needs one south to hit it? Sheesh, who'da thunk finding the shortest distance between two points would be so hard. Seeing it on a graph it seems simple, but once I draw the blocks and see the patterns go all wonky at times, I start to wonder if I can really screw this up and not do it right.

I was trying to think of a good example, but all I can think of is Minecraft. Looking here at the pocket edition I can see that the map has coordinates for where you are in-world... but how does the labeling of the blocks work? I am not interested in the depth; I can mess around with that much, much later when I get better at this. Is this a complicated process or am I just getting overwhelmed due to my lack of sleep?

I am going to bed, so no rush on the advice. I am very curious how the logic works and feel this would be a good exercise to test what I have learned the past few days, so maybe I can pull this off and learn something else while I do. Sleep well, friends. Goodnight.

Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
• 1
When modeling some idea in code, there's almost never one correct way to do it. You can do it in many different ways, and each way you do it has its own advantages and disadvantages. This is really where most of the art and creativity is in when you're designing a program.

I once did a programming workshop where all the participants got an assignment to make a simple game (I don't even remember exactly what the game was). You could choose any programming language you like and design it however you wanted. There were about 25 participants, and at the end of the evening we looked at each other's solutions. It was amazing and very interesting to see the variety, and the many different ways in which people modeled the game logic in code.

If you have this idea as you described in your post, then first think it through a bit (I see you're already doing that) and then just try putting it into code. You'll discover what the advantages and disadvantages are of the way you've modeled it. Then think about how you could do things differently and try that. You'll learn a lot about designing programs.

Chris Pow
Greenhorn
Posts: 7
I really like this post and the response. I am a very new to all of this but I read A LOT. One truth that I have found to this point(after 17 years) of building electrical systems and data networks from the ground up, is that there is always more than one way to get the job done. With that said, I believe that this is or probably is true of programming. The point I want to make is, that , just like a fingerprint, no one way of getting the job done is the same. My logic doesn't = your logic but I bet you a hundred dollars to a dohnut, when the idea is completed, it will do the same job. The only difference is.....wait for it.......experience!!! Been there done that. Time to learn something new. The great thing about learning is....with an open mind, the questions come just as fast as the mistakes. If you aren't F%\$#n' it up, you ain't learning. So, read a book or two, God bless ya and F\$^# something up like you won't have the chance tomorrow. LOL

Paul Clapham
Sheriff
Posts: 22832
43
And one advantage of programming is, if you make a mistake when you're putting your program together, you don't set your garage on fire when you try to run it!

fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
• 1
I would say that your subject should be "I was thinking...yeah - that's AWESOME".

it is amazing how many people believe that programming is about tying into a computer. Real programming is actually 80-90% thinking, and only 10-20% typing.

Junilu Lacar
Sheriff
Posts: 11493
180
Paul Clapham wrote:And one advantage of programming is, if you make a mistake when you're putting your program together, you don't set your garage on fire when you try to run it!

There was this one guy who was trying to automate his house with X10... he had a refrigerator in the basement and another one in the garage and, well...

And then there was that business with the rocket and the floating point conversion error.

Never underestimate the extent of damage a programming error can cause.

(Ok, that first example is made up but the second one actually happened in June 1996)

Campbell Ritchie
Marshal
Posts: 56553
172
Junilu Lacar wrote: . . .t the second one actually happened in June 1996)