I’m a beginner programmer looking to tweak a project. I did not include code as I have no clue where to start. Basically, I’m capturing input for different airline ticket classes. Such as: type 1 for 1st class, 2 for business, and 3 for economy. Then the input is run through if else statements to determine the cost of each ticket depending on the class. After the price is figured out and passed to another method for calculation with discount rate, I want to display the class type in the output window.
For further clarity it would say something like, (name + “Your class type is: ” + classType + “Your discount price is: ” + discountPrice + “Your finalPrice is:” + finalPrice)…..plus all the formatting elegance. I would like classType to display the actual word instead of just “1” “2” or “3”. I’ve been able to, at least, capture the input and assign prices then calculate. I just wish after doing this that I could return a string value instead of the numeric type. To those who help, thank you much and please remember I’m a noob and haven’t had the opportunity to learn arrays and anything more complicated than that.
Since it’s a simple enough scenario, you can do something like this:
The “proper” way to do a type-to-string mapping (and just using types in general) is to use
enum‘s: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html(Update): As requested for a way to do this without arrays: