Please scroll down for latest Programs. 👇
Week 01 : Programming Assignment 1
Write a Java program to check if a given integer is even or odd.
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question.
Think of it like a programming puzzle.
(Ignore presentation errors
("passed with presentation error" means
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 | Even | Even | Passed |
Week 01 : Programming Assignment 2
Write a Java program to calculate the volume of a cylinder given its radius and height.
Formula:
You can use Math.PI for the computation.
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question.
Think of it like a programming puzzle.
(This question can be solved in just one line of code)
("passed with presentation error" means
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3.5
5.0 | Volume is: 192.42 | Volume is: 192.42 | Passed |
Week 01 : Programming Assignment 3
Write a Java program to print the multiplication table of a given number up to 5.
NOTE:
Print EXACTLY as shown in the sample output.
DO NOT MISS a single space otherwise you will not be scored.
(Ignore presentation errors
("passed with presentation error" means
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
5 x 5 = 25 | 5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
5 x 5 = 25 | Passed |
Week 01 : Programming Assignment 4
Complete the code fragment that reads two integer inputs from keyboard and compute the quotient and remainder.
(Ignore presentation errors
("passed with presentation error" means
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 556
9 | The Quotient is = 61\n
The Remainder is = 7 | The Quotient is = 61\n
The Remainder is = 7 | Passed |
Week 01 : Programming Assignment 5
Write a program which will print a pattern of "*" 's of height "n".
For example:
Input:
n = 3
Output:
***
**
*
**
***
NOTE:
Print the pattern EXACTLY, without extra spaces.
("passed with presentation error" means
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 6 | ******\n
*****\n
****\n
***\n
**\n
*\n
**\n
***\n
****\n
*****\n
****** | ******\n
*****\n
****\n
***\n
**\n
*\n
**\n
***\n
****\n
*****\n
****** | Passed |
Week 02 : Programming Assignment 1
Write a Java program to create a class Student with the following attributes: name, age, and grade. Create a constructor to initialize these attributes. Display the student’s information using a method displayInfo().
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question.
Think of it like a programming puzzle.
(Ignore presentation errors
("passed with presentation error" means
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Rahul
29
A | Student Name: Rahul\n
Age: 29\n
Grade: A | Student Name: Rahul\n
Age: 29\n
Grade: A | Passed |
Week 02 : Programming Assignment 2
Write a program that demonstrates constructor overloading. Create a class Student
with two constructors:
- A constructor that accepts
name
andage
- A constructor that accepts all three attributes:
name
,age
, andgrade
.
Print the student's information using a method displayInfo()
.
Input:
name
(String)age
(int)grade
(String, optional)
Output:
The program should output:
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Rahul
30
A | Name: Rahul\n
Age: 30\n
Grade: A | Name: Rahul\n
Age: 30\n
Grade: A | Passed |
Week 02 : Programming Assignment 3
Write a program to demonstrate the use of this
keyword. Create a class Rectangle
with attributes length
and breadth
. Write a constructor to initialize these values. Also, define a method area()
to return the area of the rectangle.
Input:
Two integers: length and breadth of the rectangle.
Output:
Print the area of the rectangle.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5
10 | 50 | 50 | Passed |
Week 02 : Programming Assignment 4
Create a class Car
with attributes brand
and price
. Add a method display()
to show the car details. Write a program to create two objects of this class and display their details.
Input:
Two lines, each containing:
- Car brand (a single word)
- Car price (an integer)
Output:
Print the brand and price of both cars.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Maruti
500000
Honda
800000 | Car 1: Maruti, Price: 500000\n
Car 2: Honda, Price: 800000 | Car 1: Maruti, Price: 500000\n
Car 2: Honda, Price: 800000\n
| Passed after ignoring Presentation Error |
Week 02 : Programming Assignment 5
Write a Java program to demonstrate the concept of encapsulation by modeling a Book object. The program should include methods for setting and getting the title and author of the book, and a method to display the details of the book.
Task:
Create a class
Book
with the following private attributes:title
(String)author
(String)
Include the following methods in the
Book
class:setTitle(String title)
to set the title of the book.setAuthor(String author)
to set the author of the book.getTitle()
to return the title of the book.getAuthor()
to return the author of the book.displayDetails()
to print the details of the book in the format
In the
main()
method, create an object of theBook
class, set the title and author, and then call thedisplayDetails()
method to print the book details.
Input:
- The first line contains the title of the book (a single word).
- The second line contains the author's name (a single word).
Output:
Print the details of the book in the format:
Example:
Input:
Output:
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | DataStructures
Alice | Title: DataStructures\n
Author: Alice | Title: DataStructures\n
Author: Alice | Passed |
Week 03 : Programming Assignment 1
Write a program to print the factorial of a number by defining a static recursive method named 'Factorial'.
Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.-
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
Also,
1! = 1
0! = 1
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 120 | 120 | Passed |
Week 03 : Programming Assignment 2
There are two class cls1 and cls2 which is subclass of cls1. cls1 having a method "add" which add two numbers. Create two method inside cls2 which will take 2 parameters as input i.e. a and b and print the sum , multiplication and sum of their squares i.e (a^2) + (b^2) (name the function task())
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
4 | 6\n
8\n
20 | 6\n
8\n
20 | Passed |
Week 03 : Programming Assignment 3
Complete the code segment to count number of digits in an integer using while loop.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will always get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 153 | 3 | 3 | Passed |
Test Case 2 | 0003452 | 4 | 4 | Passed |
Week 03 : Programming Assignment 4
A Student class with private fields (name, age) is provided,
Your task is to make the following:
§ a parameterized constructor to initialize the private fields
§ the getter/setter methods for each field
Follow the naming convention as given in the main method of the suffix code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | John
20 | Name: John, Age: 20 | Name: John, Age: 20 | Passed |
Test Case 2 | Alice
25 | Name: Alice, Age: 25 | Name: Alice, Age: 25 | Passed |
Week 03 : Programming Assignment 5
This program is an exercise to call static and non-static methods.
A partial code is given defining two methods, namely sum( ) and multiply ( ).
You have to call these methods to find the sum and product of two numbers.
Complete the code segment as instructed.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
5 | 8\n
15 | 8\n
15 | Passed |
Week 04 : Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | JOY WITH JAVA | Course: JOY WITH JAVA | Course: JOY WITH JAVA\n
| Passed after ignoring Presentation Error |
Week 04 : Programming Assignment 2
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. You should use predefined class Calendar defined in java.util package.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Current Year: 2025 | Current Year: 2025\n
| Passed after ignoring Presentation Error |
Week 04 : Programming Assignment 3
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 with some bugs in it. Debug the code to execute the program successfully.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | This is large\n
This is medium\n
This is small\n
This is extra-large | This is large\n
This is medium\n
This is small\n
This is extra-large\n
| Passed after ignoring Presentation Error |
Week 04 : Programming Assignment 4
Complete the code segment to call the default method in the interface First and Second.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
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 04 : Programming Assignment 5
Modify the code segment to print the following output.
-----------------OUTPUT-------------------
Circle: This is Shape1
Circle: This is Shape2
-------------------------------------------------
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Circle: This is Shape1\n
Circle: This is Shape2 | Circle: This is Shape1\n
Circle: This is Shape2\n
| Passed after ignoring Presentation Error |
Week 05 : Programming Assignment 1
An interface Number is defined in the following program.
You have to declare a class A, which will implement the interface Number.
Note that the method findSqr(n) will return the square of the number n.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 12 | 144 | 144 | Passed |
Week 05 : Programming Assignment 2
This program is to find the GCD (greatest common divisor) of two integers writing a recursive function findGCD(n1,n2).
Your function should return -1, if the argument(s) is(are) negative (zero is allowed).
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 20 30 | 10 | 10 | Passed |
Test Case 2 | 2 -1 | -1 | -1 | Passed |
Week 05 : Programming Assignment 3
Complete the code segment to catch the ArithmeticException in the following, if any.
On the occurrence of such an exception, your program should print “Exception caught: Division by zero.”
If there is no such exception, it will print the result of division operation on two integer values.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 5 | 0 | 0 | Passed |
Test Case 2 | 20 0 | Exception caught: Division by zero. | Exception caught: Division by zero. | Passed |
Week 05 : Programming Assignment 4
In the following program, an array of integer data to be initialized.
During the initialization, if a user enters a value other than integer value, then it will throw InputMismatchException exception.
On the occurrence of such an exception, your program should print “You entered bad data.”
If there is no such exception it will print the total sum of the array.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
5 2 1 | 8 | 8 | Passed |
Test Case 2 | 2
1 h | You entered bad data. | You entered bad data. | Passed |
Week 05 : Programming Assignment 5
In the following program, there may be multiple exceptions.
You have to complete the code using only one try-catch block to handle all the possible exceptions.
For example, if user’s input is 1, then it will throw and catch “java.lang.NullPointerException“.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | No exception | No exception | Passed |
Test Case 2 | 1 | java.lang.NullPointerException | java.lang.NullPointerException | Passed |
Test Case 3 | 0 | java.lang.ArithmeticException: / by zero | java.lang.ArithmeticException: / by zero | Passed |
Week 06 : Programming Assignment 1
Complete the code segment to print the following using the concept of extending the Thread class in Java:
-----------------OUTPUT-------------------
Thread is Running.
-------------------------------------------------
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Thread is Running. | Thread is Running. | Passed |
Week 06 : Programming Assignment 2
In the following program, a thread class ThreadRun is created using the Runnable interface which prints "Thread using Runnable interface". Complete the main class to create a thread object of the class ThreadRun and run the thread.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Thread using Runnable interface. | Thread using Runnable interface. | Passed |
Week 06 : Programming Assignment 3
A part of the Java program is given, which can be completed in many ways, for example using the concept of thread, etc. Follow the given code and complete the program so that your program prints the message "NPTEL Java". Your program should utilize the given interface/ class.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | NPTEL Java | NPTEL Java | Passed |
Week 06 : Programming Assignment 4
Execution of two or more threads occurs in a random order. The keyword synchronized
in Java is used to control the execution of threads in a specific sequence. In the following program, some numbers are expected to be printed. Use the synchronized
keyword appropriately to ensure that the program prints the output in the following order:
-----------------OUTPUT-------------------
5
10
15
20
25
100
200
300
400
500
-------------------------------------------------
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | 5\n
10\n
15\n
20\n
25\n
100\n
200\n
300\n
400\n
500 | 5\n
10\n
15\n
20\n
25\n
100\n
200\n
300\n
400\n
500\n
| Passed after ignoring Presentation Error |
Week 06 : Programming Assignment 5
Add necessary codes to print the following:
-----------------OUTPUT-------------------
Name of thread 't':Thread-0
New name of thread 't':NPTEL
Thread is running.
-------------------------------------------------
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Name of thread 't':Thread-0\n
New name of thread 't':NPTEL\n
Thread is running. | Name of thread 't':Thread-0\n
New name of thread 't':NPTEL\n
Thread is running.\n
| Passed after ignoring Presentation Error |
Week 07 : Programming Assignment 1
Implement a Simple Calculator
A Calculator
class is provided. Your task is to implement the following:
A parameterized constructor to initialize two numbers.
Methods for addition, subtraction, multiplication, and division.
The division method should handle division by zero and print "Cannot divide by zero!" if attempted.
Follow the naming conventions in the given template code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 10 5 | Sum: 15\n
Difference: 5\n
Product: 50\n
Quotient: 2 | Sum: 15\n
Difference: 5\n
Product: 50\n
Quotient: 2\n
| Passed after ignoring Presentation Error |
Week 07 : Programming Assignment 2
Implement a Simple Counter
A Counter
class is provided. Implement:
A constructor initializing the counter to zero.
Methods to
increment()
,decrement()
, andgetValue()
.Ensure the counter does not go below zero.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | 1 | 1\n
| Passed after ignoring Presentation Error |
Week 07 : Programming Assignment 3
Implement a Basic Employee Class
An Employee
class is provided. Implement:
A constructor to initialize name and salary.
A method
getDetails()
to return "Employee: Name, Salary: X" format.
Example Input:
Alice 50000
Example Output:
Employee: Alice, Salary: 50000
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Deepak 50000 | Employee: Deepak, Salary: 50000.0 | Employee: Deepak, Salary: 50000.0 | Passed |
Week 07 : Programming Assignment 4
Implement a Simple Array Processor
You need to complete the implementation of the getMax()
method inside the NumberArray
class. This method should return the largest number from the array.
Tasks:
- Complete the
getMax()
method in the template section. - The method should iterate through the array and find the largest value.
getMax()
method in the template section.Example Input:
3 8 1 5 7
Example Output:
Max: 8, Min: 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3 8 1 5 7 | Max: 8, Min: 1 | Max: 8, Min: 1\n
| Passed after ignoring Presentation Error |
Week 07 : Programming Assignment 5
Implement a Simple Password Validator
In this task, you need to implement a password validation system using Java. The goal is to check if a given password meets the following conditions:
- Minimum Length Requirement: The password must be at least 8 characters long.
- Uppercase Letter Requirement: The password must contain at least one uppercase letter (A-Z).
- Number Requirement: The password must contain at least one numeric digit (0-9).
If the password meets all three conditions, print "Valid Password"
. Otherwise, print "Invalid Password"
.
Input Format:
- A single string representing the password (can contain alphabets, numbers, and special characters).
Output Format:
- Print "
Valid Password"
if the password satisfies all the conditions. - Otherwise, print "
Invalid Password"
.
Example Input:
Password123
Example Output:
Valid Password
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Password123 | Valid Password | Valid Password | Passed |
Week 08 : Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 640 | 10 | 10 | Passed |
Week 08 : Programming Assignment 2
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 120 | 120 | Passed |
Week 08 : Programming Assignment 3
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1005 | 5001 | 5001 | Passed |
Week 08 : Programming Assignment 4
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 10 | Not Prime | Not Prime | Passed |
Week 08 : Programming Assignment 5
The program should:
- - Read two matrices from user input.
- - Validate that matrix multiplication is possible (columns of first == rows of second).
- - Compute the product of the matrices.
- - Display the resulting matrix.
Input:
Output:
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2 3
1 2 3
4 5 6
3 2
7 8
9 10
11 12 | 58 64\n
139 154 | 58 64\n
139 154\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 1
Write suitable code to develop a 2D Flip-Flop Array with dimension 5 × 5, which replaces all input elements with values 0 by 1 and 1 by 0. An example is shown below:
INPUT:
00001
00001
00001
00001
00001
OUTPUT:
11110
11110
11110
11110
11110
Note the following points carefully:
1. Here, the input must contain only 0 and 1.
2. The input and output array size must be of dimension 5 × 5.
3. Flip-Flop: If 0 then 1 and vice-versa.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 00001
00001
00001
00001
00001 | 11110\n
11110\n
11110\n
11110\n
11110 | 11110\n
11110\n
11110\n
11110\n
11110\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 2
A program needs to be developed which can mirror reflect any 5 × 5 2D character array into its side-by-side reflection. Write suitable code to achieve this transformation as shown below:
INPUT: OUTPUT:
OOXOO OOXOO
OOXOO OOXOO
XXXOO OOXXX
OOOOO OOOOO
XOABC CBAOX
Note the following points carefully:
1. Here, instead of X and O any character may be present.
2. The input and output array size must be of dimension 5 × 5 and nothing else.
3. Only side-by-side reflection should be performed i.e. ABC || CBA.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | OOXOO
OOXOO
XXXOO
OOOOO
XOABC | OOXOO\n
OOXOO\n
OOXXX\n
OOOOO\n
CBAOX | OOXOO\n
OOXOO\n
OOXXX\n
OOOOO\n
CBAOX\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 3
Complete the code to perform a 45 degree anti clock wise rotation with respect to the center of a 5 × 5 2D Array as shown below:
INPUT:
00100
00100
11111
00100
00100
OUTPUT:
10001
01010
00100
01010
10001
Note the following points carefully:
1. Here, instead of 0 and 1 any character may be given.
2. The input and output array size must be of dimension 5 × 5 and nothing else.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 00100
00100
11111
00100
00100 | 10001\n
01010\n
00100\n
01010\n
10001 | 10001\n
01010\n
00100\n
01010\n
10001\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 4
Complete the code to develop an ADVANCED CALCULATOR that emulates all the functions of the GUI Calculator as shown in the image.
1. Use only double datatype to store all numeric values.
2. Each button on the calculator should be operated by typing the characters from 'a' to 'p'.
3. To calculate 25-6, User should input fjhkc (where, f for 2, j for 5, h for '-', k for 6 and c for '=' ).
3. You may use the already defined function gui_map(char).
4. Without '=', operations won't give output as shown in Input_2 and Output_2 example below.
5. The calculator should be able to perform required operations on two operands as shown in the below example:
Input_1:
klgc
Output_1:
18.0
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | klgc | 18.0 | 18.0 | Passed |
Week 09 : Programming Assignment 5
Complete the code to develop a BASIC CALCULATOR that can perform operations like Addition, Subtraction, Multiplication and Division.
Note the following points carefully:
1. Use only double datatype to store calculated numeric values.
2. Assume input to be of integer datatype.
3. The output should be rounded using Math.round() method.
4. Take care of the spaces during formatting output (e.g., single space each before and after =).
5. The calculator should be able to perform required operations on a minimum of two operands as shown in the below example:
Input:
5+6
Output:
5+6 = 11
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5+6 | 5+6 = 11 | 5+6 = 11 | Passed |
Week 10 : Programming Assignment 1
Write a Java program that connects to a database using JDBC (Java Database Connectivity).
However, the code will not compile unless you import the correct packages.
Your task is to add the correct import
statements so that the program compiles and runs properly.
Even if you have never worked with JDBC, this is a basic puzzle-style task.
Simply use your understanding of Java import statements and hints in the code to figure out what to include at the top.
📌 Hint: JDBC is part of
java.sql
, and you might needjava.lang
too (which is imported automatically, but keep it for good practice).
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | true | true | Passed |
Week 10 : Programming Assignment 2
Java uses JDBC drivers to connect to different databases.
Each database (like SQLite, MySQL, PostgreSQL, etc.) has its own JDBC driver.
This program checks whether the SQLite JDBC driver is available in the classpath.
To do that, Java uses Class.forName(...)
to try to load the driver class by its name.
Your task is to complete one line of code to load the SQLite driver and print true
if the driver is successfully loaded.
This is a common step when using JDBC in real-world applications, and this exercise helps you get comfortable with how drivers are managed.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | true | true\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 3
Once a JDBC driver is available, the next step is to establish a connection to a database.
In this task, your job is to connect to a SQLite database using the correct JDBC method.
Java provides the class DriverManager
with a method getConnection(String url)
to establish the connection.
Your task is to complete the program by writing one line that uses DriverManager.getConnection(...)
to connect to the database.
You are not required to write any SQL queries or manage database content.
The focus is on learning how to establish a basic JDBC connection.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | true | true\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 4
Create a Table in a SQLite Database Using JDBC
Once a connection to a database is established, SQL commands can be executed using JDBC.
In this task, your job is to create a table named students
with the following columns:
roll
– an integer that represents the student’s roll numbername
– a string (up to 30 characters) representing the student’s name
You will complete one line of code that executes a SQL CREATE TABLE
statement using a Statement
object.
You are not required to insert or retrieve any data — only to create the table using proper JDBC methods.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | success | success\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 5
Insert a Record into a Table Using JDBC
Once a table is created in a database, we can insert records into it using SQL INSERT
statements.
In this task, your goal is to insert a single student record into the existing students
table.
You are provided with the following variables:
roll
– an integer roll numbername
– a string representing the student’s name
Your task is to write one line of code that inserts this data into the table using a PreparedStatement
.
This is a common and safe way to insert data, as it avoids issues like SQL injection and improper formatting.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1
Alice | inserted | inserted\n
| Passed after ignoring Presentation Error |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.