Support me : Subscribe to the YouTube Channel : Swayam Solver
Week 1: Programming Assignment 1
Due on 2023-08-10, 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 ".
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
2.0
12.566370614359172\n
12.566370614359172
12.566370614359172\n
12.566370614359172
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Week 1 : Programming Assignment 2
Due on 2023-08-10, 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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
-4 -2 -5
-2
-2
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Test Case 2
Passed
Week 1 : Programming Assignment 3
Due on 2023-08-10, 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
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
1
0
0
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Test Case 2
Passed
Week 1 : Programming Assignment 4
Due on 2023-08-10, 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 = 13+53+33, 370, 371, 407, etc.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
203
0
0
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Test Case 2
Passed
Week 1 : Programming Assignment 5
Due on 2023-08-10, 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.
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 .
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
8
13
13\n
Passed after ignoring Presentation Error
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed
Week 3 : Programming Assignment 2
Due on 2023-08-17, 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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
2.0 3.0
1.0 2.0
1.4142135623730951
1.4142135623730951
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Week 3 : Programming Assignment 3
Due on 2023-08-17, 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.
Public Test Cases
Input
Expected Output
Actual Output
Status
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 Evaluation
Status
Test Case 1
Passed
Week 3 : Programming Assignment 4
Due on 2023-08-17, 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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
3 5
8\n
15
8\n
15
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Week 3 : Programming Assignment 5
Due on 2023-08-17, 23:59 IST
Complete the code segment to swap two numbers using call by object reference.
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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NPTEL JAVA
Course: NPTEL JAVA
Course: NPTEL JAVA\n
Passed after ignoring Presentation Error
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Week 4 : Programming Assignment 2
Due on 2023-08-24, 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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
Current Year: 2023\n
Current Month: 8
Current Year: 2023\n
Current Month: 8
Passed
Private Test cases used for Evaluation
Status
Test Case 1
Passed
Week 4 : Programming Assignment 3
Due on 2023-08-24, 23:59 IST
The program in this assignment is attempted to print the following output:
-----------------OUTPUT-------------------
This is large
This is medium
This is small
This is extra-large
-------------------------------------------------
However, the code is intentionally injected with some bugs. Debug the code to execute the program successfully.
Sample solutions (Provided by instructor)
1
interfaceExtraLarge{
2
staticStringextra="This is extra-large";
3
voiddisplay();
4
}
5
6
classLarge {
7
publicvoidPrint() {
8
System.out.println("This is large");
9
}
10
}
11
12
classMediumextendsLarge {
13
publicvoidPrint() {
14
System.out.println("This is medium");
15
super.Print();
16
}
17
}
18
classSmallextendsMedium {
19
publicvoidPrint() {
20
System.out.println("This is small");
21
super.Print();
22
}
23
}
24
classQuestion43implementsExtraLarge{
25
publicstaticvoidmain(String[] args) {
26
Smalls=newSmall();
27
s.Print();
28
Question43q=newQuestion43();
29
q.display();
30
}
31
publicvoiddisplay(){
32
System.out.println(extra);
33
}
34
}
Private Test cases used for evaluation
Input
Expected Output
Actual Output
Status
Test Case 1
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
The due date for submitting this assignment has passed.
1 out of 1 tests passed.
You scored 100.0/100.
Week 4 : Programming Assignment 4
Due on 2023-08-24, 23:59 IST
Complete the code segment to call the default method in the interface First and Second.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
Default method implementation of First interface.\n
Default method implementation of Second interface.
Default method implementation of First interface.\n
Default method implementation of Second interface.\n
Passed after ignoring Presentation Error
Week 4 : Programming Assignment 5
Due on 2023-08-24, 23:59 IST
Modify the code segment to print the following output.
-----------------OUTPUT-------------------
Circle: This is Shape1
Circle: This is Shape2
-------------------------------------------------
Private Test cases used for evaluation
Input
Expected Output
Actual Output
Status
Test Case 1
Circle: This is Shape2\n
Circle: This is Shape1
Circle: This is Shape2\n
Circle: This is Shape1\n
Passed
The due date for submitting this assignment has passed.
1 out of 1 tests passed.
You scored 100.0/100.
Assignment submitted on 2023-02-15, 21:26 IST
Your last recorded submission was :
1
// Interface ShapeX is created
2
interfaceShapeX {
3
publicStringbase="This is Shape1";
4
publicvoiddisplay1();
5
}
6
7
// Interface ShapeY is created which extends ShapeX
8
interfaceShapeYextendsShapeX {
9
publicStringbase="This is Shape2";
10
publicvoiddisplay2();
11
}
12
13
// Class ShapeG is created which implements ShapeY
14
classShapeGimplementsShapeY {
15
publicStringbase="This is Shape3";
16
//Overriding method in ShapeX interface
17
publicvoiddisplay1() {
18
System.out.println("Circle: "+ShapeX.base);
19
}
20
// Override method in ShapeY interface
21
publicvoiddisplay2(){
22
System.out.println("Circle: "+ShapeY.base);
23
}
24
}
25
26
// Main class Question
27
publicclassQuestion45{
28
publicstaticvoidmain(String[] args) {
29
//Object of class shapeG is created and display methods are called.
30
ShapeGcircle=newShapeG();
31
circle.display2();
32
circle.display1();
33
34
}
35
}
Week 5 : Programming Assignment 1
Due on 2023-08-31, 23:59 IST
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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
5
25
25
Passed
Week 5 : Programming Assignment 2
Due on 2023-08-31, 23:59 IST
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).
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
40 60
20
20
Passed
Test Case 2
2 0
2
2
Passed
Test Case 3
-1 -1
-1
-1
Passed
Week 5 : Programming Assignment 3
Due on 2023-08-31, 23:59 IST
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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
4 0
Exception caught: Division by zero.
Exception caught: Division by zero.
Passed
Test Case 2
10 3
3
3
Passed
Week 5 : Programming Assignment 4
Due on 2023-08-31, 23:59 IST
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.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
3
5 2 1
8
8
Passed
Test Case 2
2
1 1.0
You entered bad data.
You entered bad data.
Passed
Week 5 : Programming Assignment 5
Due on 2023-08-31, 23:59 IST
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“.
Complete the code segment to print the following using the concept of extending the Thread class in Java:
-----------------OUTPUT-------------------
Thread is Running.
-------------------------------------------------
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
Thread is Running.
Thread is Running.
Passed
Week 6 : Programming Assignment 2
Due on 2023-09-07, 23:59 IST
In the following program, a thread class Question62 is created using the Runnable interface Complete the main() to create a thread object of the class Question62 and run the thread. It should print the output as given below.
-----------------OUTPUT-------------------
Welcome to Java Week 6 New Question.
Main Thread has ended.
-------------------------------------------------
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
Welcome to Java Week 6 New Question.\n
Main Thread has ended.
Welcome to Java Week 6 New Question.\n
Main Thread has ended.
Passed
Week 6 : Programming Assignment 3
Due on 2023-09-07, 23:59 IST
A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc. Follow the given code and complete the program so that your program prints the message "NPTEL Java week-6 new Assignment Q3". Your program should utilize the given interface/ class.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
NPTEL Java week-6 new Assignment Q3
NPTEL Java week-6 new Assignment Q3
Passed
Week 6 : Programming Assignment 4
Due on 2023-09-07, 23:59 IST
Execution of two or more threads occurs in a random order. The keyword 'synchronized' in Java is used to control the execution of thread in a strict sequence. In the following, the program is expected to print the output as given below. Do the necessary use of 'synchronized' keyword, so that, the program prints the Final sum as given below:
-----------------OUTPUT-------------------
Final sum:6000
-------------------------------------------------
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
Final sum:6000
Final sum:6000\n
Passed after ignoring Presentation Error
Week 6 : Programming Assignment 5
Due on 2023-09-07, 23:59 IST
Given a snippet of code, add necessary codes to print the following:
-----------------OUTPUT-------------------
Name of thread 't1':Thread-0
Name of thread 't2':Thread-1
New name of thread 't1':Week 6 Assignment Q5
New name of thread 't2':Week 6 Assignment Q5 New
-------------------------------------------------
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
NA
Name of thread 't1':Thread-0\n
Name of thread 't2':Thread-1\n
New name of thread 't1':Week 6 Assignment Q5\n
New name of thread 't2':Week 6 Assignment Q5 New
Name of thread 't1':Thread-0\n
Name of thread 't2':Thread-1\n
New name of thread 't1':Week 6 Assignment Q5\n
New name of thread 't2':Week 6 Assignment Q5 New\n
Complete the following code fragment to read three integer values from the keyboard and find the sum of the values. Declare a variable "sum" of type int and store the result in it.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
1
1
1
3
3\n
Passed after ignoring Presentation Error
Week 7 : Programming Assignment 2
Due on 2023-09-14, 23:59 IST
Complete the code segment to catch the exception in the following, if any. On the occurrence of such an exception, your program should print “Please enter valid data” .If there is no such exception, it will print the "square of the number".
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
2
4
4
Passed
Test Case 2
p
Please enter valid data
Please enter valid data
Passed
Week 7 : Programming Assignment 3
Due on 2023-09-14, 23:59 IST
A byte char array is initialized. You have to enter an index value"n". According to index your program will print the byte and its corresponding char value. Complete the code segment to catch the exception in the following, if any. On the occurrence of such an exception, your program should print “exception occur” .If there is no such exception, it will print the required output.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
1
80\n
P
80\n
P
Passed
Test Case 2
24
exception occur
exception occur\n
Passed after ignoring Presentation Error
Test Case 3
4
76\n
L
76\n
L
Passed
Week 7 : Programming Assignment 4
Due on 2023-09-14, 23:59 IST
The following program reads a string from the keyboard and is stored in the String variable "s1". You have to complete the program so that it should should print the number of vowels in s1 . If your input data doesn't have any vowel it will print "0".
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
sam
1
1\n
Passed after ignoring Presentation Error
Test Case 2
eeE
3
3\n
Passed after ignoring Presentation Error
Test Case 3
10
0
0\n
Passed after ignoring Presentation Error
Week 7 : Programming Assignment 5
Due on 2023-09-14, 23:59 IST
A string "s1" is already initialized. You have to read the index "n" from the keyboard. Complete the code segment to catch the exception in the following, if any. On the occurrence of such an exception, your program should print “exception occur” .If there is no such exception, your program should replace the char "a" at the index value "n" of the "s1" ,then it will print the modified string.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
-1
exception occur
exception occur\n
Passed after ignoring Presentation Error
Test Case 2
e
exception occur
exception occur\n
Passed after ignoring Presentation Error
Test Case 3
4
NPTEaJAVA
NPTEaJAVA
Passed
Week 8 : Programming Assignment 1
Due on 2023-09-21, 23:59 IST
Write a program which will print a pyramid of "*" 's of height "n" and print the number of "*" 's in the pyramid.
Write a program to print symmetric Pascal's triangle of "*" 's of height "l" of odd length . If input "l" is even then your program will print "Invalid line number".
For example:
input : 5
output:
*
* *
* * *
* *
*
input : 6
output:
Invalid line number
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
6
Invalid line number
Invalid line number
Passed
Test Case 2
7
* \n
* * \n
* * * \n
* * * * \n
* * *\n
* *\n
*
* \n
* * \n
* * * \n
* * * * \n
* * *\n
* *\n
*\n
Passed after ignoring Presentation Error
Week 8 : Programming Assignment 5
Due on 2023-09-21, 23:59 IST
Write a program to display any digit(n) from 0-9 represented as a "7 segment display".
Thank you so much for uploading the answers sir...no words will equal to gratitude...i dont know how to show gratitude to you....thank you so much 100 times once again...your youtube channel and blog is very useful for all.. we will support you always in all forms...also my kind request please upload assignment answers and programming assignment answers for upcoming all weeks till week 12...
Thank you so much for uploading the answers sir...no words will equal to gratitude...i dont know how to show gratitude to you....thank you so much 100 times once again...your youtube channel and blog is very useful for all.. we will support you always in all forms...also my kind request please upload assignment answers and programming assignment answers for upcoming all weeks till week 12...
ReplyDeleteI will help you always sir...i will tell about our channel and blog to all friends, share to all ..
ReplyDeleteThanks sir , I am very happy given by your answer .
ReplyDelete