Artem H.

asked • 04/25/21

Method called searchGenius inputs information from user& tries to find a genius student.. Not work as expected. debug the method by 1. What line does error occur? 2. what is the error & why 3. correct

Here is a method called searchGenius inputs information from the user and tries to find a genius student. A "genius" student is considered to be one who is between 18 and 21 years of age, has "purple" hair, and gets a grade over 95 percent. If after 20 attempts, a genius is not found, then the program gives up and declares "No genius found" and returns false, otherwise it stops when the first genius is found and returns true.

This method does not work as expected. Please debug the method by 1) indicating the line at which the error occurs

2) explanation of what is the error and why it causes the dysfunctionality in the program

3) the correction that needs to be made ie either correcting the code or adding a statement(s)

public static boolean searchGenius(){

Scanner kb= new Scanner(;

boolean hairPurple=false;

boolean ageRange = false;

boolean gradeSuper=false;

boolean count20=false;

int count=0;

String hair="";

int age=0;

int grade=0;

boolean conditionsMet;


while(!(conditionsMet && count20)){

System.out.print("Please enter hair color ");;

hairPurple = hair.equalsIgnoreCase("purple");

System.out.print("Please enter age ");;

ageRange = (age>=18 && age<=21);

System.out.print("Please enter grade ");;




1 Expert Answer


Patrick B. answered • 04/25/21

4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.