• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Java Coder  RSS feed

 
Josh Hanson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I'm having a little trouble with this assignment I have for my intro to java class. I don't know where to start with this. It's already past due so I'm not looking for a straight up answer but just some logic. I'm new to coding and there are some concepts that i'm struggling with.





The assignment is: when a cell in the grid is clicked; upper-left = A0, lower-right = C2
this is the output of the code.
when you click it a spot, it displays coordinates.

x = 110
y = 106
col = 0
row = 0
x = 185
y = 182
col = 1
row = 1
x = 265
y = 253
col = 2
row = 2
x = 6
y = 8
col = -1
row = -1

Help is appreciated.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What exactly is the question?
 
Josh Hanson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I guess my question is: How do I change the output to display A0 when I click the top left box? I need to change the output so that it's not outputting coordinates but outputting the row and column. Once I see one example like A0 I think I should be good.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming the "A" is a column, how would you convert a column 0 into an "A"? Hint: check the ASCII value of "A".
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's all a matter of math and knowing what the different values you are dealing with mean. The X and Y values you are currently displaying are pixel positions. You have to translate that into the logical Row/Column values. Are you familiar with the integer operations * and / for multiplication and division? Try to see how you would do the calculations with pen and paper first. When you have your formulae, translating that into Java code is pretty straightforward.
 
Josh Hanson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ASCII Value of 'A' is 65. I didn't even know ASCII was a thing. Now converting it is my problem. originally I was going to covert 0 into A by using Integer.toString(). My biggest problem with coding is where to implement certain code.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Hanson wrote:The ASCII Value of 'A' is 65. I didn't even know ASCII was a thing. Now converting it is my problem. originally I was going to covert 0 into A by using Integer.toString().


The neat thing about ASCII (as compared to something like EBCDIC) is that the letters are contiguous. So, you can convert a number from 0 to 25 to a character from A to Z, but simply doing ...



Henry
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Hanson wrote:The ASCII Value of 'A' is 65. I didn't even know ASCII was a thing. Now converting it is my problem. originally I was going to covert 0 into A by using Integer.toString(). My biggest problem with coding is where to implement certain code.

Since you already know about methods, then the easiest way to answer the question of where to implement certain code is to break down the work into progressively smaller tasks. The details for accomplishing each task are implemented within a method. A few high-level methods will be composed methods which call other methods that contain the detailed instructions for accomplishing smaller tasks. This process of breaking down a program into small chunks is called decomposition

The char type is an integer type. That means that you can do calculations with it. For example:
 
Josh Hanson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of these tips are really helpful. And I understand them. But my problem is not only changing the coordinate positions to row/column values, but also just fundamentally understanding how to implement all of your ideas into this code. I'm so lost on where to start.

Now I that I learned this concept:



How would I implement it to my code.
Is this the right place to ask this question? I know you guys don't give straight up answers to anyone, which is helpful and I'm not asking for that, but using my code as an example would be helpful. It would give me an idea what to do in the future if I came to this problem again.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would happen if you added 'A' and the column number together? Give it a try.
 
Josh Hanson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where though?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One fundamental concept everyone learns is to separate how data is STORED from how it is DISPLAYED. As you are learning, the character 'A' is stored as "65". Dates and times are (most often) stored not like "January 27th, 1987", but as some weird number (number of milliseconds since Jan 1, 1970).

(here is the big hint): You only need to format it to a human readable form JUST as you are displaying it to the humans.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!