NPTEL Programming in Java Week11 Assignment Solution July 2023

NPTEL-Programming-in-Java-Week11-Assignment-Solution-July-2023

NPTEL Programming in Java Week11 All Programming Assignment Solutions – July – Oct 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 2023”

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

Java-Week11-Program1
				
						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();
			
			PreparedStatement preparedStmt2 = conn.prepareStatement(query);
			preparedStmt2.setInt (1, 2);
			preparedStmt2.setString (2, "John");
			preparedStmt2.setString (3, "Mayer");
			preparedStmt2.setInt(4, 22);

			preparedStmt2.execute();
				
			

Course Name : “Programming in Java 2023”

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

				
					query="UPDATE Players SET First_name='Rama',Last_name='Gopala',Age=24 WHERE UID=1;";
stmt.executeUpdate(query);
				
			

Course Name : “Programming in Java 2023”

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

Java-Week11-Program1
				
					stmt.executeUpdate("DELETE FROM Players WHERE UID = 1;");
				
			

Course Name : “Programming in Java 2023”

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

Structure of Table ‘PLAYERS’ is given below:

Java-Week11-Program4
				
					            ResultSet rs = stmt.executeQuery("SELECT * FROM players;");
			int count=0,total=0;
			while(rs.next()){
				count++;
				total = total + Integer.parseInt(rs.getString(4));
			}
			
			System.out.println("Average age of players is " +(total/count));
			conn.close();
				
			

Course Name : “Programming in Java 2023”

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

				
					query = "DROP TABLE players;";
    stmt.executeUpdate(query);