0

How can I store variables in an array. With a mixture of strings, variables and information entered in textfields. With what I have below. If I wanted to store numbers, price, total, tax, and name in an array, how can I do it? Thanks in advance.

String[] numbers = { "1","2", "3", "4", "5", "6" };

double price = 50.0;
double total = 100.0;

JComboBox tax = new JComboBox(numbers);
JFormattedTextField name = new JFormattedTextField();
2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by NycNessyness
0

I assume each of those attributes are related. If so, you should probably encapsulate that information into an object, and then store those objects in an array.

0

How can I go about doing that. I've been searching and I'm currently unable to find the answer. I'm familiar with setting arrays of the same type, but when they're different, that's where I'm lost.

0

I don't see why you would want to create an array containing different data types, and as far as I know, you can't.

What I assume is that you are trying to implement some sort of store where products have a price, tax etc. This would mean this information needs to be kept tied together and an array is not the best way to do this. Use an object (new class) where you store the price, tax, etc (if you store it as an object, the data types are completely up to you and you are essentially creating your own data type).

After you do that, all you need to do is create an array of your type.

Is that clearer?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.