NPTEL Programming In Java ASSIGNMENT 5 Answers 2022

NPTEL Programming In Java ASSIGNMENT 5

Are you looking for the Answers to NPTEL Programming In Java ASSIGNMENT 5? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course NPTEL Programming In Java Assignment 5

What is Programming In Java?

With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

Below you can find the answers for NPTEL Programming In Java ASSIGNMENT 5

Assignment No.Answers
Programming In Java Assignment 1 Click Here
Programming In Java Assignment 2 Click Here
Programming In Java Assignment 3 Click Here
Programming In Java Assignment 4 Click Here
Programming In Java Assignment 5 Click Here
Programming In Java Assignment 6 Click Here
Programming In Java Assignment 7 Click Here
Programming In Java Assignment 8 Click Here

NPTEL Programming In Java ASSIGNMENT 5 Answers:-

Q1. An interface Number is defined in the following program.  You have to declare a class A, which will implement the interface Number. Note that the method findSqr(n) will return the square of the number n.

MCQ ASSIGNMENT WEEK 5 ANSWERS:- CLICK HERE

//Create a class A which implements the interface Number.
class A implements Number {
  	//Define a method to find the square of a number
	 int i, square;
	 public int findSqr(int i) {
		 square=i*i;
            return square;		 
      }
}

Q2. This program isto find the GCD (greatest common divisor) of two integers writing a recursive function findGCD(n1,n2). Your function should return -1, if the argument(s) is(are) other than positive number(s).

//Create a class B, which implements the interface GCD.
class B implements GCD {
    int n1,n2;
        
    //Create a method to calculate GCD
    public int findGCD(int n1, int n2){
		if(n1==0&& n2==0) {
			return -1;
		}
		else if(n2 == 0){
			return n1;
		}
		
		else {
			return findGCD(n2, n1%n2);
		}
        }
 }

???? Next Week Answers: Assignment 06 ????

quizxp telegram

Q3. Complete the code segment to catch the ArithmeticException in the following, if any. On the occurrence of such an exception, your program should print “Exception caught: Division by zero.” If there is no such exception, it will print the result of division operation on two integer values.

int result;  
       a = input.nextInt();
       b = input.nextInt();
  
      // try block to divide two numbers and display the result
         try {
              result = a/b;
              System.out.println(result);
     	     }
          // catch block to catch the ArithmeticException
          catch (ArithmeticException e) {
             System.out.println("Exception caught: Division by zero.");
          }

Salesforce off campus Drive 2022 | Intern | Any Graduate | Bangalore/Hyderabad

Q4. In the following program, an array of integer data to be initialized. During the initialization, if a user enters a value other than integer value, then it will throw InputMismatchException exception. On the occurrence of such an exception, your program should print “You entered bad data.” If there is no such exception it will print the total sum of the array.

//Define try-catch block to save user input in the array "name",if there is an exception then catch the exception otherwise print the total sum of the array.
try{
       for(int i=0;i<length;i++){  
          int userInput=sc.nextInt();
          name[i] = userInput;
          sum=sum+name[i]; 
          } 
        System.out.println(sum);
        }
       catch(InputMismatchException e) {
        System.out.println("You entered bad data.");
        }
 

Q5. In the following program, there may be multiple exceptions. You have to complete the code using only one try-catch block to handle all the possible exceptions.

For example, if user’s input is 1, then it will throw and catch “java.lang.NullPointerException“.

   try {
	         switch (i) {
		    case 0 : 
			int zero = 0; 
			j = 92/ zero; 		
			break;
		    case 1 : 
			int b[ ] = null; 
			j = b[0] ; 	
			break;
	           default:
		       System.out.println("No exception");
		    } 		
	      }
            // catch block			
		catch (Exception e) {		
		   System.out.println(e) ;
		}

For other courses answers:- Visit

For Internship and job updates:- Visit

Disclaimer: We do not claim 100% surety of answers, these answers are based on our sole knowledge, and by posting these answers we are just trying to help students, so we urge do your assignment on your own.

if you have any suggestions then comment below or contact us at [email protected]

If you found this article Interesting and helpful, don’t forget to share it with your friends to get this information.