mardi 20 août 2019

Why if statements are overlapping

I have a code to analyze Hebrew words in entered in an edit text field. My problem is that the if statements are over lapping. And I don't know What can I do to stop the overlap. My idea to analyze the word are based on 2 elements, first element is the suffix of the word) and second element is how many letters left after removing the suffix. The result I expect is to give me the form and the simple. For example the word (השמעת) the suffix is (ת) represents the simple "(past)" then will have left only (השמע) which represents the infinitive form of the word.

Is there a way to make each if statement run alone? I don't want to have extra text views - I want to use only those I have created.

I tried to change my if statements too many times but didn't help

btn.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {

            // getting the word
            theVerb = editText.getText().toString();

            // if the word has the suffix of the pronoun you
            if (theVerb.endsWith(attah_att)) {
                numberOfletter = theVerb.lastIndexOf(attah_att);
                Thesubstring = theVerb.substring(0, numberOfletter);

                // Hifeel Past
                if ((Thesubstring.length() == 4) && (Thesubstring.substring(0, 1).equals("ה"))) {
                    fol = theVerb.substring(3, 4);
                    setBenyan.setText("הפעיל");
                    setZman.setText("עבר");
                    setGuf.setText("אתה/את");
                    setVerb.setText(theVerb.substring(0, 3).concat("י").concat(fol));

                }



            // if the word has no suffix (it means the word is with the pronoun he)
          if (theVerb.endsWith(hu)) {
                numberOfletter = theVerb.lastIndexOf(hu);
                Thesubstring = theVerb.substring(0, numberOfletter);

               // Hitpael Past
                if ((Thesubstring.length() == 5) && ((Thesubstring.substring(0, 2).equals("הת") || Thesubstring.substring(0, 2).equals("הש")
                        || Thesubstring.substring(0, 2).equals("הס") || Thesubstring.substring(0, 2).equals("הז")
                        || Thesubstring.substring(0, 2).equals("הצ"))) && !Thesubstring.substring(3, 4).equals("י")) {
                    fil = theVerb.substring(4, 5);

                    setBenyan.setText("התפעל");
                    setZman.setText("עבר");
                    setGuf.setText("הוא");
                    setVerb.setText(theVerb.substring(0, 4).concat(fil));
                }
            }
        }
    }
}

I expect when I run the above code to have the result of the first if only and not the second one. (It looks like I'm missing the main idea to allow the system differentiate between the 2 results) I expect for example that the second if to work if the word is השתמע

Aucun commentaire:

Enregistrer un commentaire