NPTEL Programming In Java Programming Assignment Week-4 August-2023 Swayam

 

Week 4 : Programming Assignment 1

Due on 2023-08-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.
Select the Language for this assignment. 
File name for this program : 
// Import the required package(s) and/or class(es)
import java.util.Scanner;
// Import of pre-defined package java.lang and class System and all of its member
import static java.lang.System.*;
// main class Question is created
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); 
  }
}
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
Course: NPTEL JAVA\n
Passed after ignoring Presentation Error




Private Test cases used for EvaluationStatus
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.

Select the Language for this assignment. 
File name for this program : 
// The following is the declaration of the main class named Question42
public class Question42 { 
    public static void main(String args[]){
        int year; // integer type variable to store year
// Create an object of Calendar class. 
java.util.Calendar current;
               
               // Use getInstance() method to initialize the Calendar object.
               current = java.util.Calendar.getInstance();
        
        // Initialize the int variable year with the current year
        year = current.get(current.YEAR);
// Print the current Year
        System.out.println("Current Year: "+year);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}  
}
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\n
Current Month: 8
Current Year: 2023\n
Current Month: 8
Passed




Private Test cases used for EvaluationStatus
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.

Select the Language for this assignment. 
File name for this program : 

Sample solutions (Provided by instructor)

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();  
    }
}
class Question43 implements ExtraLarge{
    public static void main(String[] args) {
        Small s = new Small();
        s.Print();
        Question43 q = new Question43();
        q.display();
    }
    public void display(){
        System.out.println(extra);
    }
} 
Private Test cases used for evaluationInputExpected OutputActual OutputStatus
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.
Select the Language for this assignment. 
File name for this program : 
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(){
// Call show() of First interface.
   First.super.show();
 
// Call show() of Second interface.
   Second.super.show();
} 
  
    public static void main(String args[]){ 
        Question44 q = new Question44(); 
        q.show(); 
    } 
}
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 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 evaluationInputExpected OutputActual OutputStatus
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 :
// 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);
}
}
 
// 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.display2();
  circle.display1();
  
 }
}


No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...