Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thank you. It's already helped me greatly, and I enjoy just reading the inputs from the other members..."

Geography

Where in the world do Tek-Tips members come from?
bper123 (Programmer)
9 Nov 06 17:00
Hi,

I need advice on the best way to handle a table or matrix solution. For example, if I have a table such as:

    A    B     C     D
1 true false false true

2 false false false false

3 false true  false false

4 false false false true

I don't want to code a bunch of 'if' statements to return the value contained in the table based on the coordinates. Doing so would be messy and hard to extend and maintain.

I know that there must be a better way to solve this in an OOP approach. I need to do this in Java. Any suggestions would be appreciated.
stevexff (Programmer)
10 Nov 06 4:39
Not sure I understand the problem. Why do you need 'if' statements to get a value out of a two-dimensional array?

Steve

"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)

bper123 (Programmer)
10 Nov 06 7:51
Sorry for the confusion. The table, or array, isn't as straight forward as it appears. Each row and column is a test condition.

For example:

What if each row represented a day of the week and each column represented some other condition and both conditions were parameters for which your processing needs to return a value.

Such as:

If the day is Friday and it's raining,then return eat soup. There can be several possibilities for each day, but the return values are constant for their respective combinations. Also imagine that there are more than 7 days of the week, and it's even possible to extend more days in the future and more conditions (rows & columns).
stevexff (Programmer)
10 Nov 06 10:10
It sounds as though it IS as straightforward as it seems. Consider a two-dimensional array of strings, 7 x 2 (MTWTFSS) x (T/F). Monday + raining => table(0, 0) = "eat soup".

If you have 'names' for your conditions, I guess you could use a couple of hashmaps to convert the string names into row and column numbers?

Steve

"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close