What I need is a programme to test the following requiremnets : *This method ret
ID: 3701302 • Letter: W
Question
What I need is a programme to test the following requiremnets :
*This method returns true if the word selected from the word list satisfies the constraints specified in the project document. Otherwise it returns false *eparam word * @return the word selected from the chooseWord method public static boolean isValidWord String word) t throw new UnsupportedOperationExceptionC"Remove this line and replace with your i mplementati public static void main(String[] args) throws IOException File f = new File("listOfWords . txt"); Random randnew Random(2018); Scanner reader- new Scanner(System.in); //Do NOT modify the lines above in this methodExplanation / Answer
Please find my implemetation.
Please let me know in case of any issue.
public static boolean isValidWord(String word) {
if(word.length() < 6)
return false;
//building the count array
int count[] = new int[26]; // for alphabets
for(int i=0; i<word.length(); i++) {
char c = word.charAt(i);
if(Character.isLetter(c)) {
c = Character.toLowerCase(c);
if(count[c] == 3) { // we have already seen this character 3 times
return false;
}else{
count[c]++;
}
}else{// curretn character is not an alphabets
return false;
}
}
return true;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.