
Patrick B. answered 04/25/21
Math and computer tutor/teacher
import java.util.Scanner;
class Artem
{
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=false;
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.nextInt(); //COMPILE ERROR: must read input as integer
ageRange = (age>=18 && age<=21);
System.out.print("Please enter grade ");
grade=kb.nextInt(); //COMPILE ERROR: must read input as integer
gradeSuper=grade>=95;
//MOVED to bottom of while: must re-test the conditions
conditionsMet=hairPurple && ageRange && gradeSuper; //moved to bottom of while loop
count++;
count20 = (count<20);
//outputs the result if the conditions are not met
if (!conditionsMet)
{
System.out.println(" No - it is not ");
System.out.println( (20-count) + " attempts remaining ");
}
else
{
break;
}
}
return(conditionsMet && count20);
}
public static void main (String args[])
{
Artem x = new Artem();
if (x.searchGenius())
{
System.out.println(" We got 'em boss !!! ");
}
else
{
System.out.println(" FAIL ");
}
}
}