Your mission is to design and implement a Java program to help students in early
ID: 3545429 • Letter: Y
Question
Your mission is to design and implement a Java program to help students in
early elementary school practice their arithmetic skills. The student will enter his or her grade
level (1, 2 or 3) and the program will respond with a menu something like the following (will
vary by grade level):
Which kind of problem do you want to practice?
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. I want to try them all
Please enter your choice (1, 2, 3, 4 or 5):
The student enters his or her choice, and the program responds by presenting the user with the
specified arithmetic problems appropriate to the student's grade level:
? 1st graders get 1-digit numbers only
? 2nd graders can get 1 or 2-digit numbers
? 3rd graders get 1, 2 or 3-digit numbers
If the student chooses the last option, the program should present a random assortment of all 4
types of problems.
The problems are presented one at a time, in groups of 10; after the tenth problem, the student is
given an opportunity to try another kind of problem or quit the program.
When a student has completed 10 problems, s/he should be given feedback about how many
answers were right or wrong in that set, and also a grand total of right and wrong answers for all
sets completed so far during this session.
Here is an example of the problems section of the program. The interface could use some
improvement! User responses are in bold type.
How much is 6 plus 17? Your answer: 21
That is incorrect. Try again.
How much is 6 plus 17? Your answer: 23
Excellent!
How much is 82 minus 24? Your answer: 58
You're right!
How much is 60 divided by 4? Your answer: 10
That's not it. Keep trying! ? Since this is primary math, we assume the student
Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class pp {
public static void main(String[] args) {
int level,choice,val1=0,val2=0,result,user,i,false_count=0,true_count=0;
Scanner in = new Scanner(System.in);
for(i=0;i<10;i++)
{
System.out.println("Enter your grade level(1,2 or 3)");
String str=in.nextLine();
level=Integer.parseInt(str);
if(level==1)
{
val1=0+(int)(Math.random()*10);
val2=1+(int)(Math.random()*9);
}
else if(level==2)
{
val1=10+(int)(Math.random()*90);
val2=10+(int)(Math.random()*90);
}
else if(level==3)
{
val1=100+(int)(Math.random()*900);
val2=100+(int)(Math.random()*900);
}
System.out.println("Which kind of problem do you want to practice?");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. I want to try them all");
System.out.println("Please enter your choice (1, 2, 3, 4 or 5):");
str=in.nextLine();
choice=Integer.parseInt(str);
int flag=1;
while(flag==1)
{
if(choice==1)
{
result=val1+val2;
while(true)
{System.out.println("How much is "+val1+" plus "+val2+" ? Your answer:");
str=in.nextLine();
user=Integer.parseInt(str);
if(user==result)
{
System.out.println("Excellent!");true_count++;
break;
}
else
{
System.out.println("That is incorrect. Try again.");false_count++;
}
}
flag=0;
}
else if(choice==2)
{
result=val1-val2;
while(true)
{System.out.println("How much is "+val1+" minus "+val2+" ? Your answer:");
str=in.nextLine();
user=Integer.parseInt(str);
if(user==result)
{
System.out.println("Excellent!");true_count++;
break;
}
else
{
System.out.println("That is incorrect. Try again.");false_count++;
}
}
flag=0;
}
else if(choice==3)
{
result=val1*val2;
while(true)
{System.out.println("How much is "+val1+" into "+val2+" ? Your answer:");
str=in.nextLine();
user=Integer.parseInt(str);
if(user==result)
{
System.out.println("Excellent!");true_count++;
break;
}
else
{
System.out.println("That is incorrect. Try again.");false_count++;
}
}
flag=0;
}
else if(choice==4)
{
result=val1+val2;
while(true)
{System.out.println("How much is "+val1+" plus "+val2+" ? Your answer:");
str=in.nextLine();
user=Integer.parseInt(str);
if(user==result)
{
System.out.println("Excellent!");true_count++;
break;
}
else
{
System.out.println("That is incorrect. Try again.");false_count++;
}
}
flag=0;
}
else if(choice==5)
{
choice=1+(int)(Math.random()*5);
continue;
}
}
}
System.out.println("Total true answer : "+true_count);
System.out.println("Total false answer : "+false_count);
System.out.println("final score : "+true_count+" out of "+(true_count+false_count));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.