test2

 avatar
rohkurd
java
3 years ago
4.3 kB
6
Indexable
	public static int num1, num2, operation, answer, problem;
    static SecureRandom randomNumbers = new SecureRandom();
	static Scanner input = new Scanner(System.in);
	
	public static void main(String[] args) {
		
		System.out.println("This Application is For student to practice on Mathmatical operations");
		
		mathmaticalApplication();
		execption();
	}
	public static void execption()
	{
     System.out.println("Any Problem (1:Yes, 2:NO)");

     problem = input.nextInt();
		if (problem == 1 )
		{
			mathmaticalApplication();
		}
		else if (problem == 2) {
			System.out.println("Bye");
		}
	}
	public static void Addition()
	{
		System.out.printf("%d + %d  = ?: ",num1 , num2);
    	System.out.println();
	    System.out.println("Answer : ");
		  while (operation ==1)
		    	
		   	{
		    	    answer = input.nextInt();    
			    	if (answer == num1 + num2)
			    	{
			    		System.out.println("Correct! ");
			    		execption();
			    	}
			    	else 
			    	{
			    		System.out.println("Try again...");
			    		answer++;
			    	}
		   	} 
	}
	public static void Subtraction()
	{
		System.out.printf("%d - %d  = ?: ",num1 , num2);
    	System.out.println();
	    System.out.println("Answer : ");
		while (operation ==2)
	    {
	    	answer = input.nextInt();
	    
	    if (answer == num1 - num2)
    	{
    		//System.out.println(answer);
    		System.out.println("Correct! ");
    		execption();
    	}
    	else 
    	{
    		//System.out.println("Answer : " +answer);
    		System.out.println("Try again...");
    		answer++;
    	}
	    } 
	}
	public static void Multiplication()
	{
		    System.out.printf("%d * %d  = ?: ",num1 , num2);
	    	System.out.println();
		    System.out.println("Answer : ");
		 while (operation == 3)
   	  {
 	    	    answer = input.nextInt();
 	    	   
 		    	if (answer == num1 * num2)
 		    	{
 		    		System.out.println("Correct! ");
 		    		execption();
 		    	}
 		    	else if (answer != num1 * num2)
 		    	{
 		    		System.out.println("Try again...");
 		    		answer++;
 		    	}
   	  }
	} 
	public static void Division()
	{
		System.out.printf("%d / %d  = ?: ",num1 , num2);
    	System.out.println();
	    System.out.println("Answer : ");
		while (operation == 4)
  	  {
	    	    answer = input.nextInt();
	    	   
		    	if (answer == num1 / num2)
		    	{
		    		//System.out.println(answer);
		    		System.out.println("Correct! ");
		    		execption();
		    	}
		    	else 
		    	{
		    		System.out.println("Try again...");
		    		answer++;
		    	}
  	  }
		
	}
	
	public static void Module()
	{
		System.out.println( num1+ " % "+ num2 + " = ? ");
    	System.out.println();
	    System.out.println("Answer : ");
		while (operation == 5)
  	  {
  		  
	    	    answer = input.nextInt();
	    	   
		    	if (answer == num1 % num2)
		    	{
		    		System.out.println("Correct! ");
		    		execption();
		    	}
		    	else 
		    	{	
		    		System.out.println("Try again...");
		    		answer++;
		    	}
		    	
  	  } 
	}
	public static void mathmaticalApplication()
	{
		System.out.println("1: Addition ");
		System.out.println("2: Subtraction ");
		System.out.println("3: Multiplication ");
		System.out.println("4: Division ");
		System.out.println("5: Modules ");
		System.out.println("Enter code of operation: ");
	   	operation = input.nextInt();

	   	System.out.println("Maximum Digits of the first Random Integer? : ");
	
	   	int firstMaxDigitNumber = input.nextInt();
	   	System.out.println("Maximum Digits of the first Random Integer? : ");
	   	int secondMaxDigitNumber = input.nextInt();
	   	
	   	num1 =   randomNumbers.nextInt((int) Math.pow(10, firstMaxDigitNumber));
	   	num2 =   randomNumbers.nextInt((int) Math.pow(10, secondMaxDigitNumber));
	   	
	   	if (operation == 1)
	   	{
	   		Addition();
	   	}
	   	else if (operation ==2)
	   	{
	   		Subtraction();
	   	}
	   	
	   	else if (operation ==3)
	   	{
	   		Multiplication();
	   	}
	   	
	   	else if (operation ==4)
	   	{
	   		Division();
	   	}
	   	else if (operation ==5)
	   	{
	   		Module();
	   	}
	}