Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

* This method returns true if the word selected from the word list satisfies the

ID: 3701388 • Letter: #

Question

* This method returns true if the word selected from the word list satisfies the constraints specified in the project document. Otherwise it returns *false. * @param word *@return the word selected from the chooseWord method public static boolean isValidWord(String word) 1 throw new UnsupportedOperationException("Remove this line and replace with your im public static void main(String[] args) throws IOException f File f-new FileC"listOfWords.txt"; Random rand-new Random(2018); Scanner reader -new Scanner(System. in); Do NOT modify the lines above in this method

Explanation / Answer

   public static boolean isValidWord(String word){
       //check if the string length is greater than 6
       if(word.length()<6){
           return false;
       }
     
       //check if any alphabet occurs for three times
       for(int i=0;i<word.length();i++){
           int count =0;
           for(int j=0;j<word.length();j++){
               if(word.charAt(i)==word.charAt(j)){
                   count++;
               }
           }
           if(count>=3){
               return false;
           }
       }
     
       //check if there are only alphabets
       if(!(word.matches("[a-zA-Z]"))){
           return false;
       }
       return true;
   }