vendredi 15 mai 2015

if else inside for loop android

This could be worse question but nothing seems to work for me , I have a database in Parse.com like this (created by someone else) :

enter image description here

now I have to put some validation :

if user's city and user's state match with the db's values the cost will be 30

if user's state matches but not the city the cost will be 50 else the cost will be 100

I write this code :

if (ClientList.size() > 0) {
                            for (int i = 0; i < ClientList.size(); i++) {
                            final   ParseObject p = ClientList.get(i);
                            String state = p.getString("State");
                            String city = p.getString("City");
                            float cost = Float.parseFloat(p.getString("CostInPrecentage"));
                             if(stateDeli.equalsIgnoreCase(state) && cityDeli.equalsIgnoreCase(city))
                                {
                                shippingCost = cost;
                                }
                                else if(stateDeli.equalsIgnoreCase(state) && !cityDeli.equalsIgnoreCase(city)) {
                                    shippingCost = cost;

                                }
                                else
                                {
                                    shippingCost = cost;
                                }

                            }

This always returns me shipping cost = 100

I tried to change if else

 if(stateDeli.equalsIgnoreCase(state))
                                    {
                                     if(cityDeli.equalsIgnoreCase(city))
                                     {
                                     shippingCost = cost;
                                     }
                                     else
                                     {
                                         shippingCost = cost;
                                     }
                                    }
                                    else
                                    {
                                        shippingCost = cost;
                                    }

This also returns me shipping cost = 100

Apart from these I tried many conditions with break also nothing seems to work perfectly . Could you please suggest how to validate this.

Aucun commentaire:

Enregistrer un commentaire