Arithmetic Testing for School Students


 

Arithmetic Testing for School Students

In this section, we have created an application that helps an elementary school student to learn arithmetic operations.

In this section, we have created an application that helps an elementary school student to learn arithmetic operations.

Arithmetic Testing for School Students

In this section, we have created an application that helps an elementary school student to learn arithmetic operations. This application allows the student to select the arithmetic operation that the student wishes to study. The student chooses arithmetic operations from menu.Based on the student choice, the application tests the user with exactly 10 questions. For each question, two random positive integers are generated.Then the student is asked to enter the answer for the arithmetic operation applied to the two numbers.if more than 7 questions are answered correctly, "Congratulations" message will get displayed. Otherwise the program should display the message "Please ask your teacher for help".

Here is the code:

import java.util.*;

public class Operations {
	public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
		Random random1 = new Random();
		Random random2 = new Random();
		int menu = 0;
		System.out.println("Test");
		System.out.println();
		System.out.println("1. Add");
		System.out.println("2. Subtract");
		System.out.println("3. Multiply");
		System.out.println("4. Divide");
		System.out.println("5. Exit");

		boolean quit = false;
		do {
			System.out.print("Please enter your choice: ");
			menu = scan.nextInt();
			System.out.println();

			switch (menu) {
			case 1:
				int r1 = 0,
				w1 = 0;
				for (int idx = 1; idx <= 10; ++idx) {
					int ran1 = random1.nextInt(50);
					int ran2 = random2.nextInt(50);
					System.out.print(ran1 + " + " + ran2 + " = ");
					int add = scan.nextInt();
					int total = ran1 + ran2;
					if (add != total) {
						w1++;
					} else {
						r1++;
					}
				}
				System.out.println("Right=" + r1);
				System.out.println("Wrong=" + w1);
				if (r1 > 7) {
					System.out.println("Congratulations!");
				} else {
					System.out.println("Please ask your teacher for 

help");
				}
				break;
			case 2:
				int r2 = 0,
				w2 = 0;
				for (int idx = 1; idx <= 10; ++idx) {
					int ran1 = random1.nextInt(50);
					int ran2 = random2.nextInt(50);
					System.out.print(ran1 + " - " + ran2 + " = ");
					int sub = scan.nextInt();
					int total = ran1 - ran2;
					if (sub != total) {
						w2++;
					} else {
						r2++;
					}
				}
				System.out.println("Right=" + r2);
				System.out.println("Wrong=" + w2);
				if (r2 > 7) {
					System.out.println("Congratulations!");
				} else {
					System.out.println("Please ask your teacher for 

help");
				}
				break;
			case 3:
				int r3 = 0,
				w3 = 0;
				for (int idx = 1; idx <= 10; ++idx) {
					int ran1 = random1.nextInt(50);
					int ran2 = random2.nextInt(50);
					System.out.print(ran1 + " * " + ran2 + " = ");
					int mul = scan.nextInt();
					int total = ran1 * ran2;
					if (mul != total) {
						w3++;
					} else {
						r3++;
					}
				}
				System.out.println("Right=" + r3);
				System.out.println("Wrong=" + w3);
				if (r3 > 7) {
					System.out.println("Congratulations!");
				} else {
					System.out.println("Please ask your teacher for 

help");
				}
				break;
			case 4:
				int r4 = 0,
				w4 = 0;
				for (int idx = 1; idx <= 10; ++idx) {
					int ran1 = random1.nextInt(50);
					int ran2 = random2.nextInt(50);
					System.out.print(ran1 + " / " + ran2 + " = ");
					int div = scan.nextInt();
					int total = ran1 / ran2;
					if (div != total) {
						w4++;
					} else {
						r4++;
					}
				}
				System.out.println("Right=" + r4);
				System.out.println("Wrong=" + w4);
				if (r4 > 7) {
					System.out.println("Congratulations!");
				} else {
					System.out.println("Please ask your teacher for 

help");
				}
				break;
			case 5:
				quit = true;
				break;
			default:
				System.out.println("Invalid Entry!");
			}
		} while (!quit);
	}
}



Ads