NPTEL Java Programming Week 11 : Programming Assignment 1-5 OCt-2023

 

Week 11 : Programming Assignment 1

Due on 2023-10-12, 23:59 IST

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

Column

UID

First_Name

Last_Name

Age

Row 1

1

Ram

Gopal

26

Row 2

2

John

Mayer

22


Your last recorded submission was on 2023-10-07, 15:18 IST
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class InsertData {
    public static void main(String args[]) {
        try {
              Connection conn = null;
              Statement stmt = null;
              String DB_URL = "jdbc:sqlite:/tempfs/db";
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
            
              // Open a connection
              conn = DriverManager.getConnection(DB_URL);
              stmt = conn.createStatement();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
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();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}catch(Exception e){ System.out.println(e);}  
    }  
}
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 11 : Programming Assignment 2

Due on 2023-10-12, 23:59 IST

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

Column

UID

First_Name

Last_Name

Age

From

1

Ram

Gopal

26

To

1

Rama

Gopala

24

Your last recorded submission was on 2023-10-07, 15:23 IST
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class UpdateData {
    public static void main(String args[]) {
        try {
              Connection conn = null;
              Statement stmt = null;
              String DB_URL = "jdbc:sqlite:/tempfs/db";
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
              String query="";
            
              // Open a connection
              conn = DriverManager.getConnection(DB_URL);
              stmt = conn.createStatement();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
query = " UPDATE Players SET First_name ='Rama',Last_name = 'Gopala',Age = 24  WHERE UID=1;";
stmt.executeUpdate(query);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
                catch(Exception e){ System.out.println(e);}  
    }  
}
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 11 : Programming Assignment 3

Due on 2023-10-12, 23:59 IST

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

Column

UID

First_Name

Last_Name

Age

Delete

1

Rama

Gopala

24

Your last recorded submission was on 2023-10-07, 15:25 IST
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class DeleteData {
    public static void main(String args[]) {
        try {
              Connection conn = null;
              Statement stmt = null;
              String DB_URL = "jdbc:sqlite:/tempfs/db";
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
              String query="";
            
              // Open a connection
              conn = DriverManager.getConnection(DB_URL);
              stmt = conn.createStatement();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
stmt.executeUpdate("DELETE FROM Players WHERE UID = 1;");
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
                catch(Exception e){ System.out.println(e);}  
    }  
}
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 11 : Programming Assignment 4

Due on 2023-10-12, 23:59 IST

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

Structure of Table 'PLAYERS' is given below:

Column

UID

First_Name

Last_Name

Age

Type

Integer

Varchar (45)

Varchar (45)

Integer

Your last recorded submission was on 2023-10-07, 15:39 IST
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class CalAverage {
    public static void main(String args[]) {
        try {
              Connection conn = null;
              Statement stmt = null;
              String DB_URL = "jdbc:sqlite:/tempfs/db";
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
              String query="";
              // Open a connection
              conn = DriverManager.getConnection(DB_URL);
              stmt = conn.createStatement();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
ResultSet rs = stmt.executeQuery("SELECT * FROM players;");
            int count=0,total=0;
            while(rs.next()){
                count++;
                total = total + Integer.parseInt(rs.getString(4));
            }
            
//Output
System.out.println("Average age of players is " +(total/count));
conn.close();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
                catch(Exception e){ System.out.println(e);}  
    }  
}
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed



Week 11 : Programming Assignment 5

Due on 2023-10-12, 23:59 IST
Complete the code segment to drop the table named ‘PLAYERS.
Your last recorded submission was on 2023-10-07, 16:05 IST
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class DropTable {
    public static void main(String args[]) {
        try {
              Connection conn = null;
              Statement stmt = null;
              String DB_URL = "jdbc:sqlite:/tempfs/db";
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
              String query="";
            
              // Open a connection
              conn = DriverManager.getConnection(DB_URL);
              stmt = conn.createStatement();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
// Write the SQL command to drop a table
    query = "DROP TABLE players;";
 
// Execute the SQL command to drop a table
    stmt.executeUpdate(query);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
                catch(Exception e){ System.out.println(e);}  
    }  
}
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.
   



Private Test cases used for EvaluationStatus
Test Case 1
Passed


No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...