NPTEL PROGRAMMING ASSIGNMENTS
Week 4 : Programming Assignment 1
Due Date of Submission 2022-02-24, 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.
public class Question41{
public static void main(String[] args) {
// Scanner object is created
Scanner scanner = new Scanner(System.in);
// Read String input using scanner class
String courseName = scanner.nextLine();
// Print the scanned String
out.println("Course: " + courseName);
}
}
Week 4 : Programming Assignment 2
Due Date of Submission 2022-02-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 class Question42 {
public static void main(String args[]){
int year;
Week 4 : Programming Assignment 3
Due Date of Submission 2022-02-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.
Week 4 : Programming Assignment 4
Due Date of Submission 2022-02-24, 23:59 IST
Complete the code segment to call the default method in the interface First and Second.
interface First{
// default method
default void show(){
System.out.println("Default method implementation of First interface.");
}
}
interface Second{
// Default method
default void show(){
System.out.println("Default method implementation of Second interface.");
}
}
// Implementation class code
class Question44 implements First, Second{
// Overriding default show method
public void show(){
}
public static void main(String args[]){
Question44 q = new Question44();
q.show();
}
}
Week 4 : Programming Assignment 5
Due Date of Submission 2022-02-24, 23:59 IST
Modify the code segment to print the following output.
-----------------OUTPUT-------------------
Circle: This is Shape1
Circle: This is Shape2
-------------------------------------------------
// Main class Question
public class Question45{
public static void main(String[] args) {
//Object of class shapeG is created and display methods are called.
ShapeG circle = new ShapeG();
circle.display1();
circle.display2();
public class Question45{
public static void main(String[] args) {
//Object of class shapeG is created and display methods are called.
ShapeG circle = new ShapeG();
circle.display1();
circle.display2();
}
}
}