-->

IQ-Calculator(Game) - David Raj

                            IQ-Calculator(Game)   -  David Raj

CODE : 

import java.lang.*;

import java.util.*;

class Iqcalculator{

    public static int div(){

        Random rand = new Random();

        int a = rand.nextInt(101)+10;

        int b = rand.nextInt(9)+1;

        int x = 0;

        if(a%b==0 && b!=1)

        {

            System.out.println(a+" / "+b);

            x = a/b;

    return check(x);

        }

        else

    return div();

}

    }

    public static int check(int x)

    {

        Scanner sc = new Scanner(System.in);

        System.out.print("enter the value : ");

        int sco = 0;

        int n = sc.nextInt();

        if(x==n)

        {

            System.out.println("Correct answer");

            sco = 10;

            return sco;

        }

        else

        {

            System.out.println("Sorry Wrong answer");

            return sco;

        }

    }

    public static void option(){

        int x =0;

        int c,d,score=0;

int option;

Random rand = new Random();

        for(int i=0; i<8; i++)

        {   

    option = rand.nextInt(4)+1;

            switch(option)

            {

                case 1: c=rand.nextInt(9)+1;

                        d=rand.nextInt(9)+1;

                        System.out.println(c+" + "+d);

                        x = c+d;

                        score += check(x);

                        break;

                case 2: c=rand.nextInt(9)+1;

                        d=rand.nextInt(9)+1;

                        if(c>d){

                        System.out.println(c+" - "+d);

                        x = c-d;

                        score += check(x);

                        }

                        else

                        {

                        System.out.println(d+" - "+c);

                        x = d-c;

                        score += check(x);

                        }

                        break;

                case 3: c=rand.nextInt(9)+1;

                        d=rand.nextInt(9)+1;

                        System.out.println(c+" * "+d);

                        x = c*d;

                        score += check(x);

                        break;

                case 4: score += div();

break;

            }

        }

        if(score>0){

double per = (score*100)/80;

        System.out.println("\nYour Score : "+per+"%");}

else{

System.out.println("\nSorry u've failed!! in the test");}

    }

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

System.out.println("press 1 to start game : ");

int n = sc.nextInt();

if(n==1){

System.out.println("Game begins!!");

    option();

}

else{

System.out.println("Error : Invalid option !!");}

}}

 Output : 

press 1 to start game :

1

Game begins!!

7 + 4

enter the value : 11

Correct answer

2 * 9

enter the value : 18

Correct answer

7 - 3

enter the value : 4

Correct answer

48 / 6

enter the value : 8

Correct answer

10 - 5

enter the value : 5

Correct answer

6 * 7

enter the value : 42

Correct answer

45 / 9

enter the value : 5

Correct answer

4 + 6

enter the value : 10

Correct answer


Your Score : 100.0%