My Java teacher hasn't been very clear, and i'm kind of flying solo here.

He gave us this project, and one part of the project is throwing up a JOptionPane which allows the user to input a number which correlates to a specific car.

For example

Choose a vehicle that you want.
1. Camaro
2. Mustang
3. Charger

(User types in number 1)

How do I pass on Camaro to the next variable instead of the number 1.

Any help is greatly appreciated. Thanks! If you need any more details just ask.

Edited 4 Years Ago by AMeddaugh: n/a

Okay so my Java teacher isn't very good, and i'm kind of flying solo here.

He gave us this project, and one part of the project is throwing up a JOptionPane which allows the user to put input a number which correlates to a specific car.

For example

How do I pass on Camaro to the next variable instead of the number 1.

Any help is greatly appreciated. Thanks! If you need any more details just ask.

So if the user types 3... the variable chosen shows 3? well then why not have an if else statement to set the appropriate string name depending on whats selected :

String variable;
if(joptionanswer==1){
variable="Camero";
} else if(joptionanswer==2){
variable="Mustang";
}

Edited 4 Years Ago by DavidKroukamp: n/a

"my Java teacher isn't very good" is a very bold, and probably inaccurate statement.
I asume you've heard of the if-else structure? if not, a switch statement could help out as well.

So if the user types 3... the variable chosen shows 3? well then why not have an if else statement to set the appropriate string name depending on whats selected :

String variable;
if(joptionanswer==1){
variable="Camero";
} else if(joptionanswer==2){
variable="Mustang";
}

That makes a lot of sense now. Not sure why it didn't really click until now thanks!

@stultuske

I changed my initial statement. I agree that perhaps him not being very good was a bit of a harsh statement. I guess I was more frustrated that he has sort of a confusing way of wording things. To the point that most of what he touched on for 30 mins in class made more sense to me after reading the book for 5 minutes.

This article has been dead for over six months. Start a new discussion instead.