QUESTION - Computers in Education Computers are playing an increasing role in education. This project is used to teach students elementary math. You are required to produce a code that is capable of doing the followings:
- At first your program need to help elementary students to learn multiplication,
- Use random to produce two positive one-digit integers.
- The program should type a question such as:
How much is 6 times 7? The following should occur:
- The student types the answer.
- Your program checks the students answer.
- If it is correct, print “very Good”, then ask another multiplication question.
- If the answer is wrong print “ No, Please try again”, then let the student try the same question repeatedly until the student finally gets is right.
You are then required to expand the program to make student learns addition, division and subtraction. Modify your code to use the random method to generate both numbers and operations. If the student gets 10 consecutive answers correctly, then the program should move to level 2 where numbers become two digits.
Challenge: The program should present the user with multiple operations for different numbers such as:
( 9 + 7 ) * 4 5 / 10 + 3 ( 6 - 5 ) / 5 9 *5 / 4
And repeat the process above
I have been working on this for so long but I just cannot seem to make it work. Can anyone tell me what is my mistake?
This is what I did :
import java.util.Random;
import java.util.Scanner;
public class ComputersInEducation {
//MULTIPLICATION
public void multiply(int a, int b) {
int correctResult = 0;
Scanner sc = new Scanner(System.in);
System.out.println("How much is "+ a +"times"+ b +"?");
while (correctResult==0) {
System.out.println("Enter multiplication result -");
int c = sc.nextInt();
if (c == a * b) {
System.out.println("Very Good");
correctResult = 1;
}else {
System.out.println("No, Please try again");
}
}
}
//ADDITION
public void sum(int a, int b) {
int correctResult = 0;
Scanner sc = new Scanner(System.in);
System.out.println("How much is"+ a +"sum"+ b +"?");
while (correctResult == 0) {
System.out.println("Enter sum result -");
int c = sc.nextInt();
if (c == (a + b)) {
System.out.println("Very Good");
correctResult = 1;
}
else {
System.out.println("No, please try again");
}
}
}
//SUBTRACTION
public void subtraction(int a, int b) {
int correctResult = 0;
Scanner sc = new Scanner(System.in);
System.out.println("How much is"+ a +"subtraction"+ b +"?");
while (correctResult == 0) {
System.out.println("Enter your subtraction result - ");
int c = sc.nextInt();
if (c == (a - b)) {
System.out.println("Very Good");
correctResult = 1;
} else {
System.out.println("No, Please try again");
}
}
}
//DIVISION
public void division(int a, int b) {
int correctResult = 0;
Scanner sc = new Scanner(System.in);
System.out.println("How much is"+ a +"division"+ b +"?");
while (correctResult == 0) {
System.out.println("Enter your division result - ");
int c = sc.nextInt();
if (c == (a / b)) {
System.out.println("Very Good");
correctResult = 1;
} else {
System.out.println("No, Please try again");
}
}
}
//ANOTHER LEVEL
public static void main(String[]args) {
Math math = new Math();
Random rn = new Random();
int max = 9;
int min = 1;
int num1 = rn.nextInt((max - min) + 1)+ min;
int num2 = rn.nextInt((max - min) + 1)+ min;
for (int i = 1; i <= 10; i++) {
math.multiply(num1, num2);
}
System.out.println("Next level!");
max = 99;
min = 10;
num1 = rn.nextInt((max - min) + 1)+ min;
num2 = rn.nextInt((max - min) + 1)+ min;
for (int i = 1; i <= 10; i++) {
math.multiply(num1, num2);
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire