vendredi 24 janvier 2020

Which methods to use instead of if-else statement?

Is there a way to reduce the amount of code with lots of condition written in java netbean? I have used if-else statement with lots of conditions and realized my code is pretty lengthy. The conditions are taken from combo box and text field(haven't added yet).

I have a sample of the code at the bottom. I need to add 20+ of this so I am not sure if if-else statement is the only option.

    if (RegionBx.getSelectedItem().equals("Tokyo") &&
        SeasonBx.getSelectedItem().equals("Spring") && 
        MealBx.getSelectedItem().equals("Nil")) {
          TravelCost = Tokyo + (Tokyo * sphotel) + (Tokyo * spflight);
    } 

Aucun commentaire:

Enregistrer un commentaire