Untitled

 avatar
unknown
java
4 years ago
2.2 kB
5
Indexable
package test1;
import java.util.Random;
import java.util.Scanner;

public class Project {

		public static void main(String[] args) {
			do { 
			int Z = 0;
			
		try (Scanner input = new Scanner (System.in)) {
			Random random = new Random();
			System.out.printf("This application is for students to practice on mathemtical operations%n%n");
			System.out.print("Maximum digits of the first random integer?");
			int X1 = input.nextInt();
			int X = random.nextInt ( (int) Math.pow(10, X1));
			
			System.out.printf("Maximum digits of the second random integer?");
			int Y1 = input.nextInt();
			int Y = random.nextInt ( (int) Math.pow(10, Y1));
			System.out.printf("Please selsect a mathmetical operation:%n%n");
			System.out.printf("1: Addition%n");
			System.out.printf("2: Subtraction%n");
			System.out.printf("3: Multiplication%n");
			System.out.printf("4: Division%n");
			System.out.printf("5: Modulus%n");
			System.out.printf("Operation Code:");
				char OPcode = input.next().charAt(0); 
				if (OPcode == '1' ){
					Z=X + Y;
					System.out.println(X +" + "+Y+" = "+" "+ "?" );
					System.out.printf( "Answer:%d%n", Z);
					System.out.print("Correct!");
				}
				else if(OPcode == '2')
				{
					Z=X-Y;
					System.out.println(X +" - "+Y+" = "+" "+ "?" );
					System.out.printf( "Answer:%d%n", Z);
					System.out.print("Correct!");
				}
				else if(OPcode == '3'){
					Z=X*Y;
					System.out.println(X +" * "+Y+" = "+" "+ "?" );
					System.out.printf( "Answer:%d%n", Z);
					System.out.print("Correct!");
				}
				else if(OPcode == '4'){
						Z=X/Y;
						System.out.println(X +" / "+Y+" = "+" "+ "?" );
						System.out.printf( "Answer:%d%n", Z);
						System.out.print("Correct!");
			    }
				else if(OPcode == '5'){
					   System.out.println("mod("+X+")="+Math.abs(X));
					   System.out.print("Correct!");
				}
				else
					
				System.out.println("Your Input is invalid.");
				
				System.out.println("Another problem? (1:Yes , 2:No:%n");
		
		
		
		char Answer = input.next().charAt(0);
		while (Answer == 1);{
			continue;
		
		
		if (Answer == 2) {
			break; 
			System.out.print("Bye");
		}
		}
		}
			}
		}
}
		
		
		
		


	


	

Editor is loading...