Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

NPTEL Programming In Java Programming Assignment Jan-2023 Swayam

 NPTEL » Programming In Java     Jan 2023 NPTEL course


  Please scroll down for latest Programs. 👇 


Support me : Subscribe to the YouTube Channel :  Swayam Solver



Week 1 : Programming Assignment 1

Due on 2023-02-09, 23:59 IST

Complete the code segment to help Ragav , find the highest mark and average mark secured by him in "s" number of subjects.

Your last recorded submission was on 2023-01-20, 12:58 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Exercise1_5{
3
    public static void main(String[] args) {
4
     Scanner input = new Scanner(System.in);
5
         double mark_avg;
6
         int result;
7
         int i;
8
         int s;
9
      //define size of array
10
       s = input.nextInt();
11
     //The array is defined "arr" and inserted marks into it.
12
      int[] arr = new int[s];   
13
      for(i=0;i<arr.length;i++)
14
      {
15
    arr[i]=input.nextInt();
16
        }
17
//Initialize maximum element as first element of the array.  
18
   //Traverse array elements to get the current max.
19
   //Store the highest mark in the variable result.
20
   //Store average mark in avgMarks.
result=arr[0];
mark_avg=0;

for(i=0;i<arr.length;i++)
      {
  mark_avg+=arr[i];
  if( arr[i]> result)
  result = arr[i];
}
mark_avg/=s;
System.out.println(result);
System.out.print(mark_avg);
0
 }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
20 50 60 40 70
70\n
48.0
70\n
48.0
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed





Week 1 : Programming Assignment 2

Due on 2023-02-09, 23:59 IST

Consider First n even numbers starting from zero(0).Complete the code segment to calculate sum of  all the numbers divisible by 3 from 0 to n. Print the sum.

Example:

Input: n = 5

-------
0 2 4 6 8
Even number divisible by 3:0 6
sum:6

Your last recorded submission was on 2023-01-20, 12:58 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Exercise1_3 {
3
       public static void main(String[] args) {
4
       Scanner sc = new Scanner(System.in);
5
       int n=sc.nextInt();
6
      int sum=0;
7
//Use for or while loop do the operation.
int i=0;
for(i=0;i<=2*n;i=i+2) //i<2*n is correct because we are started counting from 0
      {
if(i%3==0)
    sum+=i;
}
System.out.print(sum);
0
 }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
0
0
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed





Week 1: Programming Assignment 3

Due on 2023-02-09, 23:59 IST

Complete the code segment to find the perimeter and area of a circle given a value of radius.

You should use Math.PI constant in your program. If radius is zero or less than zero then print " please enter non zero positive number ".

Your last recorded submission was on 2023-01-20, 12:59 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;  
2
public class Exercise1_1 {
3
       public static void main(String[] args) {
4
Scanner s = new Scanner(System.in); 
5
       double radius= s.nextDouble();
6
       double perimeter;
7
       double area;
8
//Calculate the perimeter 
9
  //Calculate the area
if(radius < 0)
  System.out.print(" please enter non zero positive number ");
else
{
  perimeter = 2*Math.PI*radius;
  area = Math.PI*radius*radius;
  
  System.out.println(perimeter);
  System.out.print(area);
}
0
  }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2.5
15.707963267948966\n
19.634954084936208
15.707963267948966\n
19.634954084936208
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 1 : Programming Assignment 4

Due on 2023-02-09, 23:59 IST

Complete the code segment to check whether the number is an Armstrong number or not.

Armstrong Number:

A positive number is called an Armstrong number if it is equal to the sum of cubes of its digits for example 153 = 1
3+53+33, 370, 371, 407, etc.

Your last recorded submission was on 2023-01-20, 13:00 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
public class Exercise1_4 {
3
    public static void main(String[] args) {
4
       Scanner sc = new Scanner(System.in);
5
       int n=sc.nextInt();
6
           int result=0;
7
//Use while loop check the number is Armstrong or not.
8
//store the output(1 or 0) in result variable.
int sum=0;
int m=n;
int d;
while(m!=0)
{
  d=m%10;
  sum+=d*d*d;
  m/=10;
}
if(sum == n )
  result=1;
else
  result=0;
System.out.print(result);
0
 }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
203
0
0
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed






Week 1 : Programming Assignment 5

Due on 2023-02-09, 23:59 IST

Complete the code segment to find the largest among three numbers x,y, and z. You should use if-then-else construct in Java.

Your last recorded submission was on 2023-01-20, 13:01 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;  
2
public class Exercise1_2 {
3
       public static void main(String[] args) {
4
Scanner s = new Scanner(System.in); 
5
        int x = s.nextInt(); 
6
        int y = s.nextInt();
7
int z = s.nextInt();
8
int result = 0;
9
//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.
10
if(x>y)
  if(x>z)
    result=x;
  else
    result=z;
else if(y>z)
    result=y;
  else
    result = z;

System.out.print(result);
0
 }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
-4 -2 -3
-2
-2
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed




---------------------------------------------------------------------------------------------------------------------------------------------


Week 2 : Programming Assignment 1

Due on 2023-02-09, 23:59 IST
Complete the code segment to call the method  print() of class School first and then call print() method of class Student.

NOTE: Don't provide any INPUT in Sample Test Cases

Your last recorded submission was on 2023-02-09, 19:33 IST
Select the Language for this assignment. 
File name for this program : 
1
// This is the class named School
2
class School { 
3
    // This is a method in class School
4
    public void print() { 
5
        System.out.println("Hi! I class SCHOOL."); 
6
    } 
7
} 
8
// This is the class named Student
9
class Student { 
10
    // This is a method in class Student
11
    public void print() { 
12
        System.out.println("Hi! I am class STUDENT"); 
13
    } 
14
}
15
16
public class Question21{ 
17
    public static void main(String args[]){
18
19
// Create an object of class Student
20
// Call 'print()' method of class Student 
21
// Create an object of class School
22
// Call 'print()' method of class School
School sch = new School();
sch.print();
Student s = new Student();
s.print();
0
     } 
1
}
2
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Hi! I class SCHOOL.\n
Hi! I am class STUDENT
Hi! I class SCHOOL.\n
Hi! I am class STUDENT\n
Passed after ignoring Presentation Error




Private Test cases used for EvaluationStatus
Test Case 1
Passed


Week 2 : Programming Assignment 2

Due on 2023-02-09, 23:59 IST
Complete the code segment to call the method  print() of class given class Printer to print the following.

--------------------------------
Hi! I am class SCHOOL
Hi! I class STUDENT.
--------------------------------

NOTE: Don't provide any INPUT in Sample Test Cases

Your last recorded submission was on 2023-02-09, 19:34 IST
Select the Language for this assignment. 
File name for this program : 
1
// This is the class named Printer
2
class Printer { 
3
    // This are the methods in class Printer
4
    public void print() { 
5
        System.out.println("Hi! I class SCHOOL."); 
6
    } 
7
    public void print(String s) { 
8
        System.out.println(s); 
9
    } 
10
} 
11
12
public class Question22{ 
13
    public static void main(String[] args) {    
14
15
// Create an object of class Printer
Printer p = new Printer();
// Call 'print()' methods for desired output
p.print();
p.print("Hi! I am class STUDENT");
0
    }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Hi! I class SCHOOL.\n
Hi! I am class STUDENT
Hi! I class SCHOOL.\n
Hi! I am class STUDENT\n
Passed after ignoring Presentation Error




Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 2 : Programming Assignment 3

Due on 2023-02-09, 23:59 IST
Complete the code segment to call print() method of class Question by creating a method named ‘student()’.
Select the Language for this assignment. 
File name for this program : 
1
// This is the main class Question
2
public class Question23{ 
3
    public static void main(String[] args) { 
4
        // Object of the main class is created
5
        Question23 q = new Question23();
6
        // Print method on object of Question class is called
7
        q.student();
8
    }
9
    
10
    // 'print()' method is defined in class Question
11
    void print(Question23 object){
12
        System.out.print("Well Done!");
13
    }
14
15
// Define a method named 'student()' in class Question
void student(){
// Call the method named 'print()' in class Question
  print(this);
}
0
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Well Done!
Well Done!
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed





Week 2 : Programming Assignment 4

Due on 2023-02-09, 23:59 IST
Complete the code segment to call default constructor first and then any other constructor in the class.
Select the Language for this assignment. 
File name for this program : 
1
// This is the main class Question
2
public class Question214{
3
    public static void main(String[] args){
4
        Answer a = new Answer(10,"MCQ");
5
    }
6
}
7
class Answer{
    Answer(){
        System.out.println("You got nothing.");
    }
    Answer(int marks, String type){
        this();
        System.out.print("You got "+marks+" for an "+ type);
    }
}

You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
You got nothing.\n
You got 10 for an MCQ
You got nothing.\n
You got 10 for an MCQ
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 2 : Programming Assignment 5

Due on 2023-02-09, 23:59 IST
Complete the code segment to debug / complete the program which is intended to print 'NPTEL JAVA'.
Select the Language for this assignment. 
File name for this program : 
1
public class Question215{ 
2
    public static void main(String[] args) { 
3
4
  //Declare variable with name 'nptel', 'space' and 'java' and proper datatype
5
    String nptel, space, java;
6
7
  //Initialize the variables with proper input
8
    nptel = "NPTEL";
9
    space = " ";
10
    java = "JAVA";
11
12
13
// Print as per requirement
System.out.print( nptel + space + java + space + nptel);
0
   }
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
NPTEL JAVA NPTEL
NPTEL JAVA NPTEL
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



--------------------------------------------------------------------------------------------------------------------------------------



Week 3 : Programming Assignment 1

Due on 2023-02-16, 23:59 IST

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.

Your last recorded submission was on 2023-02-08, 14:56 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
3
public class Circle extends Point{
4
    
5
public static void main(String[] args) {
6
7
     Scanner sc = new Scanner(System.in);
8
     Point p1=new Point();
9
     p1.x=sc.nextDouble();
10
     p1.y=sc.nextDouble();
11
     Point p2=new Point();
12
     p2.x=sc.nextDouble();
13
     p2.y=sc.nextDouble(); 
14
     Circle c1=new Circle();
15
    c1.distance(p1,p2);
16
    
17
  }
18
19
}
20
21
//Complete the code segment to define a class Point with parameter x,y and method distance()for calculating distance between two points.
//Note: Pass objectsof type class Point as argument in distance() method. 
class Point{
  double x,y;
  public double distance(Point p1, Point p2){
    System.out.print(Math.sqrt((p1.x-p2.x) * (p1.x-p2.x)  + (p1.y-p2.y) * (p1.y-p2.y)));
    return(Math.sqrt((p1.x-p2.x) * (p1.x-p2.x)  + (p1.y-p2.y) * (p1.y-p2.y)));
  }
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2.0  3.0
1.0  2.0
1.4142135623730951
1.4142135623730951
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 3 : Programming Assignment 2

Due on 2023-02-16, 23:59 IST

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.  

Your last recorded submission was on 2023-02-08, 15:03 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class QuestionScope {
3
int sum(int a, int b){ //non-static method
4
        return a + b;
5
    }
6
static int multiply(int a, int b){ //static method
7
        return a * b;
8
    }
9
}
10
public class Exercise3_4{
11
public static void main( String[] args ) {
12
        Scanner sc = new Scanner(System.in);
13
        int n1=sc.nextInt();
14
        int n2=sc.nextInt();
15
16
//Called the method sum() to find the sum of two numbers.
//Called the method multiply() to find the product of two numbers.
QuestionScope qs = new QuestionScope();
System.out.println(qs.sum(n1,n2));
System.out.print(QuestionScope.multiply(n1,n2));
0
}
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3 5
8\n
15
8\n
15
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 3 : Programming Assignment 3

Due on 2023-02-16, 23:59 IST

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

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class Question {  //Define a class Question with two elements e1 and e2.
3
  Scanner sc = new Scanner(System.in);
4
int e1 = sc.nextInt();  //Read e1
5
int e2 = sc.nextInt();  //Read e2
6
}
7
public class Exercise{
8
// Define static method swap()to swap the values of e1 and e2 of class Question.
public static void swap(Question t)
{
  int temp = t.e1;
  t.e1 = t.e2;
  t.e2 = temp;
}
0
public static void main(String[] args) {
1
//Create an object of class Question
2
    Question t = new Question ();
3
  //Call the method swap()
4
swap(t);
5
6
System.out.println(t.e1+" "+t.e2);    
7
  }
8
9
}   
10
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
15 20
20 15
20 15\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed





Week 3 : Programming Assignment 4

Due on 2023-02-16, 23:59 IST

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 .

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner; //This package for reading input
2
public class Fibonacci { 
3
4
public static void main(String args[]) { 
5
     Scanner sc = new Scanner(System.in);
6
    int n=sc.nextInt(); //Read an integer
7
System.out.println(fib(n)); //Generate and print the n-th Fibonacci                
8
                                     //number
9
    } 
10
static int fib(int n) {
11
//complete the code segment to find the nth Fibonacci number in the Fibonacci sequence and return the value. Write the function recursively.
if (n==1)      //Terminal condition
            return 0;
        else if(n==2)
            return 1;           
return fib(n - 1) + fib(n - 2); //Recursive call of function 
0
}
1
}
2
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
0
0\n
Passed after ignoring Presentation Error
Test Case 2
3
1
1\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed





Week 3 : Programming Assignment 5

Due on 2023-02-16, 23:59 IST

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.

Select the Language for this assignment. 
File name for this program : 
1
import java.util.Scanner;
2
class Shape{
3
double length, breadth;
4
Shape(double l, double b){ //Constructor to initialize a Shape object  
5
length = l;
6
breadth= b;
7
}
8
Shape(double len){    //Constructor to initialize another Shape object  
9
length = breadth = len;
10
}
11
double calculate(){// To calculate the area of a shape object
12
return length * breadth ;
13
}
14
}
15
public class Test1 extends Shape{    
16
17
//Create a derived class constructor which can call the one parametrized constructor of the base class
18
//Create a derived class constructor which can call the two parametrized constructor of the base class
19
//Override the method calculate() in the derived class to find the volume of a shape instead of finding the area of a shape
20
//Template code:
    double height;
    Test1(double length,double h) {
//base class constructor with one parameter is called
        super(length);
        height=h;
    }
    
    Test1(double length,double breadth,double h) {
//base class constructor having two argument is called
        super(length,breadth);
        height=h;
    }

    double calculate()  {
        return length*breadth*height;
    }
0
public static void main(String args[]){
1
    Scanner sc = new Scanner(System.in);//Create an object to read                                                               
2
                                          //input
3
    double l=sc.nextDouble(); //Read length
4
    double b=sc.nextDouble(); //Read breadth    
5
    double h=sc.nextDouble(); //Read height
6
    Test1 myshape1 = new Test1(l,h);
7
    Test1 myshape2 = new Test1(l,b,h);
8
    double volume1;
9
    double volume2;
10
    volume1 = myshape1.calculate();
11
    volume2=myshape2.calculate();
12
    System.out.println(volume1);
13
    System.out.println(volume2);
14
    }
15
}
16
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2.0 3.0 4.0
16.0\n
24.0
16.0\n
24.0\n
Passed after ignoring Presentation Error






Private Test cases used for EvaluationStatus
Test Case 1
Passed



---------------------------------------------------------------------------------------------------------------




Week 4 : Programming Assignment 1

Due on 2023-02-23, 23:59 IST
Complete the code segment to execute the following program successfully. You should import the correct package(s) and/or class(s) to complete the code.
Your last recorded submission was on 2023-02-15, 15:38 IST
Select the Language for this assignment. 
File name for this program : 
1
// Import the required package(s) and/or class(es)
import java.util.*;
import static java.lang.System.out;
0
// main class Question is created
1
public class Question41{
2
  public static void main(String[] args) {
3
    // Scanner object is created
4
    Scanner scanner = new Scanner(System.in);
5
     // Read String input using scanner class
6
    String courseName = scanner.nextLine(); 
7
     // Print the scanned String
8
    out.println("Course: " + courseName); 
9
10
    LinkedList<String> cars = new LinkedList<String>();
11
    cars.add("Volvo");
12
    cars.add("BMW");
13
    cars.add("Ford");
14
    cars.add("Mazda");
15
    System.out.println(cars);
16
  }
17
}
18
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NPTEL JAVA
Course: NPTEL JAVA\n
[Volvo, BMW, Ford, Mazda]
Course: NPTEL JAVA\n
[Volvo, BMW, Ford, Mazda]\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 4 : Programming Assignment 2

Due on 2023-02-23, 23:59 IST
Complete the code segment to print the current year. Your code should compile successfully.

Note: 
In this program, you are not allowed to use any import statement. Use should use predefined class Calendar defined in java.util package.

Your last recorded submission was on 2023-02-15, 16:12 IST
Select the Language for this assignment. 
File name for this program : 
1
// The following is the declaration of the main class named Question42
2
public class Question42 { 
3
    public static void main(String args[]){
4
        int year; // integer type variable to store year
5
// Create an object of Calendar class.
6
// Use getInstance() method to initialize the Calendar object.
7
// Initialize the int variable year with the current year
java.util.Calendar cal = java.util.Calendar.getInstance();
year = cal.get(java.util.Calendar.YEAR);
0
        // Print the current Year
1
        System.out.println("Current Year: "+year);
0
  }  
1
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Current Year: 2023
Current Year: 2023\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed





Week 4 : Programming Assignment 3

Due on 2023-02-23, 23:59 IST
The program in this assignment is attempted to print the following output: 

-----------------OUTPUT-------------------
This is small
This is medium
This is large
This is extra-large
-------------------------------------------------

However, the code is intentionally injected with some bugs. Debug the code to execute the program successfully.

Your last recorded submission was on 2023-02-15, 19:37 IST
Select the Language for this assignment. 
File name for this program : 
1
interface ExtraLarge{
    static String extra = "This is extra-large";
    void display();
}

class Large {
    public void Print() {
        System.out.println("This is large");
    }
}

class Medium extends Large {
    public void Print() {
        System.out.println("This is medium");
                    super.Print();
    }
}
class Small extends Medium {
    public void Print() {
        System.out.println("This is small");
              super.Print();
    }
}
0
class Question43 implements ExtraLarge{
1
    public static void main(String[] args) {
2
        Small s = new Small();
3
        s.Print();
4
        Question43 q = new Question43();
5
        q.display();
6
    }
7
    public void display(){
8
        System.out.println(extra);
9
    }
10
} 
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
This is small\n
This is medium\n
This is large\n
This is extra-large
This is small\n
This is medium\n
This is large\n
This is extra-large\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 4 : Programming Assignment 4

Due on 2023-02-23, 23:59 IST
Complete the code segment to call the default method in the interface Second then First.
Your last recorded submission was on 2023-02-15, 16:35 IST
Select the Language for this assignment. 
File name for this program : 
1
interface First{ 
2
    // default method 
3
    default void show(){ 
4
        System.out.println("Default method implementation of First interface."); 
5
    } 
6
} 
7
  
8
interface Second{ 
9
    // Default method 
10
    default void show(){ 
11
        System.out.println("Default method implementation of Second interface."); 
12
    } 
13
} 
14
  
15
// Implementation class code 
16
class Question44 implements First, Second{ 
17
    // Overriding default show method 
18
    public void show(){
19
20
// Call show() of Second interface.
21
// Call show() of First interface.
Second.super.show();
First.super.show();
0
   } 
1
  
2
    public static void main(String args[]){ 
3
        Question44 q = new Question44(); 
4
        q.show(); 
5
    } 
6
}
7
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Default method implementation of Second interface.\n
Default method implementation of First interface.
Default method implementation of Second interface.\n
Default method implementation of First interface.\n
Passed after ignoring Presentation Error





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 4 : Programming Assignment 5

Due on 2023-02-23, 23:59 IST
Modify the code segment to print the following output.

-----------------OUTPUT-------------------
Circle: This is Shape1
Circle: This is Shape2
-------------------------------------------------

Your last recorded submission was on 2023-02-15, 17:00 IST
Select the Language for this assignment. 
File name for this program : 
1
// Interface ShapeX is created
interface ShapeX {
 public String base = "This is Shape1";
 public void display1();
}

// Interface ShapeY is created which extends ShapeX
interface ShapeY extends ShapeX {
 public String base = "This is Shape2";
 public void display2();
}

// Class ShapeG is created which implements ShapeY
class ShapeG implements ShapeY {
 public String base = "This is Shape3";
 //Overriding method in ShapeX interface
 public void display1() {
  System.out.println("Circle: " + ShapeX.base);
 }
 // Override method in ShapeY interface
  public void display2(){
  System.out.println("Circle: " + ShapeY.base);
}
}

0
// Main class Question 
1
public class Question45{
2
 public static void main(String[] args) {
3
  //Object of class shapeG is created and display methods are called.
4
  ShapeG circle = new ShapeG();
5
  circle.display2();
6
  circle.display1();
7
  
8
 }
9
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
Circle: This is Shape2\n
Circle: This is Shape1
Circle: This is Shape2\n
Circle: This is Shape1\n
Passed after ignoring Presentation Error






Private Test cases used for EvaluationStatus
Test Case 1
Passed




---------

















































4 comments:

  1. Week 2 : Programming Assignment 1 and Week 2 : Programming Assignment 2 are Wrong

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. week 5 assignment answers sir

    ReplyDelete

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.