Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that performs the following tasks. - Using an interface explain

ID: 3819401 • Letter: C

Question

Create a program that performs the following tasks.
- Using an interface explain what the program does to the user.
- Ask the user to enter two integers greater than zero.
- Code an error trap in the program to prevent the user inputting the wrong type of data
- Stop the program after three errors by the user
- Obtain the greatest common factor of the two integers and output it to the user.

Further in an excel spread sheet or similar application perform a hand trace of the program for
the two integers 375 and 405.

Explanation / Answer

please find the code in java

import java.util.Scanner;

public class FindGCF {
   public static void main(String args[]){
       Scanner sc = new Scanner(System.in);
       int count =0;
       int num1, num2;
       do{
           System.out.println(" Enter first integer greater than 0");
           num1 =sc.nextInt();
           if(num1>0){
               break;
           }
           else{
               count++;
           }
           if(count ==3){
               System.out.println("You have entered the wrong number 3 times. So, exiting the code!!");
               System.exit(0);
           }  
       }while(1==1);
      
       do{
           System.out.println(" Enter second integer greater than 0");
           num2 =sc.nextInt();
           if(num1>0){
               break;
           }
           else{
               count++;
           }
           if(count ==3){
               System.out.println("You have entered the wrong number 3 times. So, exiting the code!!");
               System.exit(0);
           }  
       }while(1==1);
      
       int gcd = findGCD(num1, num2);
       System.out.println("GCD of "+num1+" and "+num2 +" is: "+gcd);
   }
  
   public static int findGCD(int x, int y){
       if(y == 0){
           return x;
       }
       return findGCD(x, x%y);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote