NPTEL Programming in Java Week 2 Assignment Solution 2023

Programming-In-Java-Week2-Programming-Assignment-Solutions

NPTEL Programming in Java Week 2 All Programming Assignment Solutions – July 2022 | Swayam. 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.

COURSE LAYOUT
    • Week 1 : Overview of Object-Oriented Programming and Java
    • Week 2 : Java Programming Elements
    • Week 3 : Input-Output Handling in Java
    • Week 4 : Encapsulation
    • Week 5 : Inheritance
    • Week 6 : Exception Handling
    • Week 7 : Multithreaded Programming
    • Week 8 : Java Applets and Servlets
    • Week 9 : Java Swing and Abstract Windowing Toolkit (AWT)
    • Week 10 : Networking with Java
    • Week 11: Java Object Database Connectivity (ODBC)
    • Week 12: Interface and Packages for Software Development

Course Name : “Programming in Java 2023”

Question : 1  Complete the code segment to call the method  print() of class School first and then call print() method of class Student.

				
					// This is the class named School
class School { 
    // This is a method in class School
    public void print() { 
		System.out.println("Hi! I class SCHOOL."); 
    } 
} 
// This is the class named Student
class Student { 
	// This is a method in class Student
    public void print() { 
		System.out.println("Hi! I am class STUDENT"); 
    } 
}

public class Question21{ 
    public static void main(String args[]){
    	// Creating object of class School
        School school = new School();
		// Call 'print()' method of class School
		school.print();
		// Creating object of class Student
		Student student = new Student();
		// Call 'print()' method of class Student
		student.print();

	}
}
		
				
			

Question : 2 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.
——————————–
				
					// This is the class named Printer
class Printer { 
    // This are the methods in class Printer
    public void print() { 
		System.out.println("Hi! I class SCHOOL."); 
    } 
    public void print(String s) { 
		System.out.println(s); 
    } 
} 

public class Question22{ 
    public static void main(String[] args) {
      // Create an object of class Student
      Printer ptr = new Printer();
      // Call 'print()' method of class Student 
      ptr.print();
	  // Create an object of class Student
      Printer stu = new Printer();
      // Call 'print()' method of class Student 
      stu.print("Hi! I am class STUDENT");
    }
}

				
			

Question : 3 Complete the code segment to call print() method of class Question by creating a method named ‘student()’.

				
					// This is the main class Question
public class Question23{ 
    public static void main(String[] args) { 
		// Object of the main class is created
		Question23 q = new Question23();
		// Print method on object of Question class is called
		q.studentMethod();
    }
	
	// 'print()' method is defined in class Question
	void print(Question23 object){
		System.out.print("Well Done!");
	}
// Define a method named 'studentMethod()' in class Question
void student(){
    // Call the method named 'print()' in class Question
    print(this);
    }
}
				
			

Question : 4 Complete the code segment to call default constructor first and then any other constructor in the class.

				
					// This is the main class Question
public class Question214{
	public static void main(String[] args){
		Answer a = new Answer(10,"MCQ");
	}
}
class Answer{
	// This is the default constructor of the class Answer
	Answer(){
		System.out.println("You got nothing.");
	}
	// This is a parameterized constructor of the class Answer
	Answer(int marks, String type){
		//The 'this()' referene variable is able to call the default constructor of the class.
		this();		
		//Print marks and type of the question
		System.out.print("You got "+marks+" for an "+ type);
	}
}
				
			

Question : 5 Complete the code segment to debug / complete the program which is intended to print ‘NPTEL JAVA’.

				
					public class Question215{ 
    public static void main(String[] args) { 
    //Declare variable with name 'nptel', 'space' and 'java' and proper datatype.
	String nptel,space,java;
	//Initialize the variables with proper input
	nptel="NPTEL";
	space=" ";
	java="JAVA";
	System.out.print(nptel+space+java+space+nptel);
   }
}