NPTEL Programming in Java Week 11 Assignment Solution 2023

NPTEL Programming in Java Week 11 Assignment Solution

NPTEL Programming in Java Week 11 All Programming Assignment Solutions – January 2023 | 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 July 2023”

Question : 1 Complete the code segment to insert the following data using prepared statement in the existing table ‘PLAYERS.

				
					String query = " insert into PLAYERS (UID, first_name, last_name, age)"  + " values (?, ?, ?, ?)";

			PreparedStatement preparedStmt = conn.prepareStatement(query);
			preparedStmt.setInt (1, 1);
			preparedStmt.setString (2, "Ram");
			preparedStmt.setString (3, "Gopal");
			preparedStmt.setInt(4, 26);

			preparedStmt.execute();
	  
			preparedStmt.setInt (1, 2);
			preparedStmt.setString (2, "John");
			preparedStmt.setString (3, "Mayer");
			preparedStmt.setInt(4, 22);

			preparedStmt.execute();
				
			

Course Name : “Programming in Java July 2023”

Question : 2 Write the required code in order to update the following data in the table ‘PLAYERS

				
					// write SQL command to update table data
query="UPDATE Players SET First_name ='Rama',Last_name = 'Gopala',Age = 24  WHERE UID=1;";
// Execute the SQL command to update the table data
stmt.executeUpdate(query);

				
			

Course Name : “Programming in Java July 2023”

Question : 3 Write the appropriate code in order to delete the following data in the table ‘PLAYERS.

				
					// Execute the command in order to delete a row from the table
stmt.executeUpdate("DELETE FROM Players WHERE UID = 1;");
				
			

Course Name : “Programming in Java July 2023”

Question : 4 Complete the following program to calculate the average age of the players in the table ‘PLAYERS.

				
								query = "insert into Players (UID, first_name, last_name, age)"  + "values (?, ?, ?, ?)";
			preparedStmt.setInt (1, 1);
			preparedStmt.setString (2, "Rama");
			preparedStmt.setString (3, "Gopala");
			preparedStmt.setInt(4, 24);
			preparedStmt.execute();
			preparedStmt.setInt (1, 2);
			preparedStmt.setString (2, "John");
			preparedStmt.setString   (3, "Mayer");
			preparedStmt.setInt(4, 22);
			preparedStmt.execute();
			preparedStmt.setInt (1, 3);
			preparedStmt.setString (2, "Leo");
			preparedStmt.setString   (3, "Martin");
			preparedStmt.setInt(4, 27);
			preparedStmt.execute();

			ResultSet result = stmt.executeQuery("SELECT * FROM players;");
			int num=0,all=0;
			while(result.next())
            {
				num++;
				all = all + Integer.parseInt(result.getString(4));
			}
			//Output
			System.out.println("Average age of players is " +(all/num));
			conn.close(); 
				
			

Course Name : “Programming in Java July 2023”

Question : 5 Complete the code segment to drop the table named ‘PLAYERS.

				
					// Write the SQL command to drop a table
query = "DROP TABLE players;";
// Execute the SQL command to drop a table
stmt.executeUpdate(query);