# giving a choice selection a double value

grant keiter
Greenhorn
Posts: 6
I am writing a program to serve as a point of sale device for a restauraunt(not for real, final project in class). Anyway, I have some choice selections in my program, such as an appetizer. I need to be able to assign each appetizer a numerical value, to be used in calculation of a sub total, and total. I am not finding anything giving a good example, in my text, nor in some other books I have. I have been scowering the net, but I guess I am not looking for the right thing, or have found it and just dont know it.
If anyone has any Idea how I do this I would appreciate it.

miguel lisboa
Ranch Hand
Posts: 1281
a good way to start would be posting what you wrote so far, so that members could help you out

grant keiter
Greenhorn
Posts: 6
Sorry, should have done so. I think that I have possibly figured it out. I am not sure, stuck on another problem right now, so I can not get any calculations or results to display.

but I have tried something like this.

double a2 = 3.5;
String Queso = Double.toString(a2);

grant

grant keiter
Greenhorn
Posts: 6
Well I found this does not work. When I select the Calculate button on my app, it gives me the choices selected, but the actual choice. not a numeric value?

I was hoping, that with the code combined above would give me a numeric value. But I just get something like QuesoBurritoSoda in the total Field.

Layne Lund
Ranch Hand
Posts: 3061
I'm not entirely clear on your question. What does this numerical value represent? Is it the price for the item? If so, you should use the name "price" instead of "a2". In fact, "a2" is a poor variable name since it does not describe what the variable means. You should pick a more descriptive name so that you (and others) can understand your code more easily.

With that said, can you be more specific about what you need help with? Like I said earlier, I don't understand what this numerical value is for. Also, do you have a class that represents individual items? This might be helpful, but I'm not entirely sure since you haven't posted enough of your code yet in order for me to get a clear picture of what is happening.

Layne

grant keiter
Greenhorn
Posts: 6
the numerical value will be the price of the item. I had chosen a2, becaue that was meant to represent the second appetizer choice. I do not have a clas s that represents each Item. There are just items added to a choice menu.

here is the part of my code that I am trying to get the numerical values to show up in.

grant keiter
Greenhorn
Posts: 6
Well, this here has me worried. If I am reading this correct, it is telling me that there is no way to take a string value of a choice, and when selected have that return a double, or integer.

have a look at it and tell me if I am wrong

http://www.coderanch.com/t/391111/java/java/choice-field

grant keiter
Greenhorn
Posts: 6
So, I am still workin on my problem. It has been over 24 hours, I am not sure If I should give up on it, The only problem is I fear I have tried to do something that can not be done. Right now I have tried going with a combobox, just do not have the knowledge to complete it, aslo tried checkbox to the same conclusion. I am regretting the fact that the course is online, and my teacher is in Germany. It is nice to have the freedom, but it seems every other post of a student I read through, they have a much better understanding of the language. Scotch is kicking in now.

My latest idea has been an if statement.

such as stating if the ChoiceItem Chips_and_Salsa is selected double appetizerPrice = 2.50;

if ChoiceItem Queso is selected double
appetizerPrice = 3.50;\

and so on.

This has not returned favorable results, well no results at all, I am getting incompatible types with code the likes of:

well I think I should sleep on this until tommorrow, I should have 15 or so hours to work on it.

Thank you for the help