• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help with arraylist problem  RSS feed

 
donga lonka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am new to this forum, and i am new to java. The question is that i have created an imaginary table, and i will take the input column and input row from the user to point to a specific cell within that table. The tric that if the user inputted the same cell, the program wouldn't allow him to do so. I tried alot to do it but i actually gave up now cause i simply couldn't do it. This is the code:


That doesn't work because i have failed to store each 2 numbers in one index of the arraylist, so i had to store column and row in a seprate indexes.

For example if i entered 12 it would output "continue" which is fine and if entered 34 it would also output "continue", but then if i entered 2 3 it would output "you've pointed at this cell " which is not true

Any Ideas?

Many Thanks!
}
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than using two parallel ArrayList<Integer>, why not one ArrayList<SomeClass> where SomeClass holds two ints together. You could create your own class for this or use the java.awt.Point class.

Best of luck!

Also, perhaps the mods would like to move this to the Beginner's forum since it seems to belong there.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
donga lonka wrote:For example if i entered 12 it would output "continue" which is fine and if entered 34 it would also output "continue", but then if i entered 2 3 it would output "you've pointed at this cell " which is not true


I can't follow because you've to enter 2 numbers before the output. But why don't you use an cell[][] in which cell is a class/interface with a method isUsed() or something like that. If you want more flexibility then you could use
ArrayLists.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch ! The next time you post code in your message, please use code tags. I have added them for you.
 
donga lonka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem that if i stored it in the arrylist as a class, i don't really know how to compare the 2 integers in that index.

Will you tell me how to compare them please?


Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!