# NPTEL Programming In Java Assignment 3 Answers 2022

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

## 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 3

## NPTEL Programming In Java Assignment 3 Answers:-

Q1.This program is related to the generation of Fibonacci numbers.

For example: 0,1, 1,2, 3,5, 8, 13,… is a Fibonacci sequence where 13 is the 8th Fibonacci number.

A partial code is given and you have to complete the code as per the instruction given below.

``````if (n==1)
return 0;
else if(n==2)
return 1;
return fib(n - 1) + fib(n - 2); ``````

Q2. Define a class Point with two fields x and y each of type double. Also, define a method distance(Point p1, Point p2) to calculate the distance between points p1 and p2 and return the value in double.

Complete the code segment given below. Use Math.sqrt( ) to calculate the square root.

``````
class Point{
double x;
double y;

public static void distance(Point p1,Point p2){
double d;
d=Math.sqrt((p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y));
System.out.println(d);
}
}  ``````

???? Next Week Answers: Assignment 04 ????

Q3. A class Shape is defined with two overloading constructors in it. Another class Test1 is partially defined which inherits the class Shape. The class Test1 should include two overloading constructors as appropriate for some object instantiation shown in main() method. You should define the constructors using the super class constructors. Also, override the method calculate( ) in Test1 to calculate the volume of a Shape.

``````//Create a derived class constructor which can call the one parametrized constructor of the base class
//Create a derived class constructor which can call the two parametrized constructor of the base class
//Override the method calculate() in the derived class to find the volume of a shape instead of finding the area of a shape

double height;
Test1(double length,double h) {

super(length);
height=h;
}

height=h;
}

double calculate()	{
}``````

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

Q4. This program to exercise the call of static and non-static methods. A partial code is given defining two methods, namely sum( ) and multiply ( ). You have to call these methods to find the sum and product of two numbers. Complete the code segment as instructed.

``````//Called the method sum() to find the sum of two numbers.
//Called the method multiply() to find the product of two numbers.

QuestionScope st = new QuestionScope();
int result1=st.sum(n1,n2);
int result2=QuestionScope.multiply(n1,n2);

System.out.println(result1);
System.out.println(result2);``````

Q5. Complete the code segment to swap two numbers using call by object reference.

``````static void swap(Question obj)
{
int temp;
temp=obj.e1;
obj.e1=obj.e2;
obj.e2=temp;
}``````