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(System.in);

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;

conditionsMet=hairPurple&&ageRange&&gradeSuper;

while(!(conditionsMet && count20)){

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

hair=kb.next();

hairPurple = hair.equalsIgnoreCase("purple");

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

age=kb.next();

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

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

grade=kb.next();

gradeSuper=grade>=95;


}

}






1 Expert Answer

By:

Patrick B. answered • 04/25/21

Tutor
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.

OR

Find an Online Tutor Now

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