Your program should meet one of the requirements. The program extends ConsolePro
ID: 3623682 • Letter: Y
Question
Your program should meet one of the requirements. The program extends ConsoleProgram( java--textpad, compiler)
* It should ask a series of 5 questions. As with any such Limit, the number of questions should be coded as a name constant so that it can be easily be changed.
*Each question should consist of a single addition or subtraction problem involving just two numbers such as "What is 2+5? or what is "11- 7?"
The type of problem addition or subtraction should be chosen randomly for each question
*None of the numbers involved including the answer, should be less than 0 or greater than 20.(This restriction mean that the program should never ask questions like "What is 11+16?" or "What is 7-9?" but your program should choose the numbers randomly.
* The program should give the students 3 chances to answer each question. If the students get the right answer the programs should indicate that in some proper way and go on to the next questions. If the students does not get the answer in 3 tries, the program should give the answer and go on to another problem.
Even though the program is designed to offer encouragement when the students responds correctly, the monotonous repetition of a sentence like " That's the answer!" has opposite effect after a while. To add variety, choose among 4 or 5 different messages when the students get the right answer.
Explanation / Answer
please rate - thanks
get back to me if any problems
import java.util.*;
public class mathTutor
{public static void main(String [] args)
{final int questions=5;
int op,num1,num2,result,ans,tries,i,mess;
char cop;
boolean correct;
Scanner in=new Scanner(System.in);
Random r=new Random();
for(i=1;i<=questions;i++)
{System.out.println("Question number "+i);
do{
num1=r.nextInt(21);
num2=r.nextInt(21);
op=r.nextInt(2);
if(op==0)
{result=num1+num2;
cop='+';
}
else
{result=num1-num2;
cop='-';
}
}while(result<0||result>20);
tries=0;
correct=false;
do
{System.out.print("What is "+num1+cop+num2+"? ");
ans=in.nextInt();
if(result==ans)
{correct=true;
mess=r.nextInt(5);
switch(mess)
{case 0: System.out.println(":) :) :) Nice");
break;
case 1: System.out.println("You did it!");
break;
case 2: System.out.println("Congrats-that's right");
break;
case 3: System.out.println("Good job!");
break;
case 4: System.out.println("Nice work");
break;
}
}
else
{ tries++;
if(tries<3)
System.out.println("Sorry, that's not right-try again");
else
{System.out.println("Study this one-the correct answer is "+result);
correct=true;
}
}
}while(!correct);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.