Course Code : BCSL-146
Course Title : Object Oriented Programming using Java Lab
Assignment Number : BCA_NEW (4)/L-146/Assignment/2026
Maximum Marks : 50
Weightage : 25% [Link]
Last Date of Submission : 30th April, 2026 (for January 2026 session)
: 31st October, 2026 (for July 2026 session)
Note: - This assignment only for students, not for sell or re-upload any media or website. All right reserve to "IGNOU Study Helper". It is illegal to share or
reupload it. If anything like this is found, then appropriate action will be taken and apply copyright ACT to you. You will be responsible for illegal work. So
don't share and upload on any media.
Question 1: Write a program to demonstrate use of different operators in Java.
Ans.
public class OperatorsDemo {
public static void main(String[] args) {
int a = 10, b = 5;
// Arithmetic Operators
[Link]("Arithmetic Operators:");
[Link]("a + b = " + (a + b));
[Link]("a - b = " + (a - b));
[Link]("a * b = " + (a * b));
[Link]("a / b = " + (a / b));
[Link]("a % b = " + (a % b));
// Relational Operators
[Link]("\nRelational Operators:");
[Link]("a > b = " + (a > b));
[Link]("a < b = " + (a < b));
[Link]("a == b = " + (a == b));
[Link]("a != b = " + (a != b));
// Logical Operators
[Link]("\nLogical Operators:");
boolean x = true, y = false;
[Link]("x && y = " + (x && y));
[Link]("x || y = " + (x || y));
[Link]("!x = " + (!x));
// Assignment Operators
[Link]("\nAssignment Operators:");
int c = a;
c += b;
[Link]("c += b -> " + c);
c -= b;
Ignou Study Helper-Sunil Poonia Page 1
[Link]("c -= b -> " + c);
// Unary Operators
[Link]("\nUnary Operators:");
int d = 7;
[Link]("d = " + d);
[Link]("++d = " + (++d));
[Link]("--d = " + (--d));
// Bitwise Operators
[Link]("\nBitwise Operators:");
int m = 6, n = 3;
[Link]("m & n = " + (m & n));
[Link]("m | n = " + (m | n));
[Link]("m ^ n = " + (m ^ n));
}
}
Output:
Arithmetic Operators:
a + b = 15
a-b=5
a * b = 50
a/b=2
a%b=0
Relational Operators:
a > b = true
a < b = false
a == b = false
a != b = true
Logical Operators:
x && y = false
x || y = true
!x = false
Assignment Operators:
c += b -> 15
c -= b -> 10
Unary Operators:
d=7
++d = 8
--d = 7
Bitwise Operators:
Ignou Study Helper-Sunil Poonia Page 2
m&n=2
m|n=7
m^n=5
Question 2: Write java programs to demonstrate use of abstract class and interface. Make necessary assumptions.
Ans.
Java Program to Demonstrate Abstract Class
Assumption: We create an abstract class Shape that contains an abstract method area(). Two classes Rectangle and Circle
extend the abstract class and implement the method.
abstract class Shape {
// Abstract method
abstract void area();
}
// Subclass 1
class Rectangle extends Shape {
int length = 10;
int width = 5;
void area() {
int result = length * width;
[Link]("Area of Rectangle: " + result);
}
}
// Subclass 2
class Circle extends Shape {
double radius = 4;
void area() {
double result = 3.14 * radius * radius;
[Link]("Area of Circle: " + result);
}
}
public class AbstractClassDemo {
public static void main(String[] args) {
Shape s1 = new Rectangle();
[Link]();
Shape s2 = new Circle();
[Link]();
}
}
Ignou Study Helper-Sunil Poonia Page 3
Output:
Area of Rectangle: 50
Area of Circle: 50.24
Java Program to Demonstrate Interface
Assumption:
We create an interface Vehicle that contains methods start() and stop(). A class Car implements this interface.
interface Vehicle {
void start();
void stop();
}
class Car implements Vehicle {
public void start() {
[Link]("Car starts with a key.");
}
public void stop() {
[Link]("Car stops using brakes.");
}
}
public class InterfaceDemo {
public static void main(String[] args) {
Car c = new Car();
[Link]();
[Link]();
}
}
Output:
Car starts with a key.
Car stops using brakes.
Question 3: Write a java program to demonstrate use of thread priority and how interthread communications take place.
Ans. A Java program that demonstrates:
1. Thread Priority (how threads are given different priorities)
2. Inter-thread Communication using wait() and notify() methods.
Assumption: A producer thread produces numbers and a consumer thread consumes them from a shared object.
Java Program: Thread Priority and Inter-Thread Communication
class SharedResource {
int number;
boolean available = false;
Ignou Study Helper-Sunil Poonia Page 4
// Producer method
synchronized void produce(int value) {
try {
while (available) {
wait(); // wait until value is consumed
}
number = value;
[Link]("Produced: " + number);
available = true;
notify(); // notify consumer
} catch (InterruptedException e) {
[Link](e);
}
}
// Consumer method
synchronized void consume() {
try {
while (!available) {
wait(); // wait until value is produced
}
[Link]("Consumed: " + number);
available = false;
notify(); // notify producer
} catch (InterruptedException e) {
[Link](e);
}
}
}
// Producer Thread
class Producer extends Thread {
SharedResource resource;
Producer(SharedResource r) {
resource = r;
}
public void run() {
for (int i = 1; i <= 5; i++) {
[Link](i);
}
}
}
// Consumer Thread
Ignou Study Helper-Sunil Poonia Page 5
class Consumer extends Thread {
SharedResource resource;
Consumer(SharedResource r) {
resource = r;
}
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]();
}
}
}
public class ThreadCommunicationDemo {
public static void main(String[] args) {
SharedResource resource = new SharedResource();
Producer p = new Producer(resource);
Consumer c = new Consumer(resource);
// Setting thread priorities
[Link](Thread.MAX_PRIORITY); // Priority 10
[Link](Thread.MIN_PRIORITY); // Priority 1
[Link]("Producer Priority: " + [Link]());
[Link]("Consumer Priority: " + [Link]());
[Link]();
[Link]();
}
}
Output:
Producer Priority: 10
Consumer Priority: 1
Produced: 1
Consumed: 1
Produced: 2
Consumed: 2
Produced: 3
Consumed: 3
Produced: 4
Consumed: 4
Produced: 5
Ignou Study Helper-Sunil Poonia Page 6
Consumed: 5
Question 4: Write java program to demonstrate useJavaFX in GUI development.
Ans. Java Program Using JavaFX
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class JavaFXDemo extends Application {
@Override
public void start(Stage primaryStage) {
// Create Label
Label label = new Label("Welcome to JavaFX GUI");
// Create Button
Button button = new Button("Click Me");
// Action when button is clicked
[Link](e -> {
[Link]("Button Clicked!");
});
// Layout
VBox layout = new VBox(10);
[Link]().addAll(label, button);
[Link]([Link]);
// Scene
Scene scene = new Scene(layout, 300, 200);
[Link]("JavaFX Example");
[Link](scene);
[Link]();
}
public static void main(String[] args) {
launch(args);
}
}
Ignou Study Helper-Sunil Poonia Page 7
Output:
Welcome to JavaFX GUI
[ Click Me ]
Button Clicked!
Question 5: Write a program using JDBC for developing simple CRUD application for billing of a Medical Store. Use
appropriate GUI components in your application. Make necessary assumptions.
Ans. Java program using JDBC with GUI (Swing) to demonstrate a simple CRUD application for a Medical Store Billing System.
Assumptions
i. Database: MySQL
ii. Database name: medical_store
iii. Table name: medicine
iv. Fields: id, name, price, quantity
v. JDBC Driver: MySQL Connector/J
vi. GUI: Java Swing
SQL Table
CREATE DATABASE medical_store;
USE medical_store;
CREATE TABLE medicine (
id INT PRIMARY KEY,
name VARCHAR(50),
price DOUBLE,
quantity INT
);
Java Program (JDBC + GUI CRUD)
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class MedicalStoreCRUD extends JFrame implements ActionListener {
JTextField idField, nameField, priceField, quantityField;
JButton addBtn, updateBtn, deleteBtn, viewBtn;
JTextArea outputArea;
Connection con;
MedicalStoreCRUD() {
setTitle("Medical Store Billing System");
Ignou Study Helper-Sunil Poonia Page 8
// Labels
JLabel idLabel = new JLabel("Medicine ID:");
JLabel nameLabel = new JLabel("Name:");
JLabel priceLabel = new JLabel("Price:");
JLabel quantityLabel = new JLabel("Quantity:");
// Text Fields
idField = new JTextField(10);
nameField = new JTextField(10);
priceField = new JTextField(10);
quantityField = new JTextField(10);
// Buttons
addBtn = new JButton("Add");
updateBtn = new JButton("Update");
deleteBtn = new JButton("Delete");
viewBtn = new JButton("View");
outputArea = new JTextArea(10, 30);
// Layout
setLayout(new FlowLayout());
add(idLabel); add(idField);
add(nameLabel); add(nameField);
add(priceLabel); add(priceField);
add(quantityLabel); add(quantityField);
add(addBtn);
add(updateBtn);
add(deleteBtn);
add(viewBtn);
add(new JScrollPane(outputArea));
// Button actions
[Link](this);
[Link](this);
[Link](this);
[Link](this);
// Database Connection
try {
con = [Link](
"jdbc:mysql://localhost:3306/medical_store",
"root",
"password"
Ignou Study Helper-Sunil Poonia Page 9
);
} catch (Exception e) {
[Link](e);
}
setSize(400, 400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
try {
int id = [Link]([Link]());
String name = [Link]();
double price = [Link]([Link]());
int quantity = [Link]([Link]());
if ([Link]() == addBtn) {
PreparedStatement ps = [Link](
"INSERT INTO medicine VALUES (?, ?, ?, ?)");
[Link](1, id);
[Link](2, name);
[Link](3, price);
[Link](4, quantity);
[Link]();
[Link]("Record Added Successfully");
}
if ([Link]() == updateBtn) {
PreparedStatement ps = [Link](
"UPDATE medicine SET name=?, price=?, quantity=? WHERE id=?");
[Link](1, name);
[Link](2, price);
[Link](3, quantity);
[Link](4, id);
[Link]();
[Link]("Record Updated Successfully");
}
if ([Link]() == deleteBtn) {
PreparedStatement ps = [Link](
"DELETE FROM medicine WHERE id=?");
[Link](1, id);
[Link]();
[Link]("Record Deleted Successfully");
}
if ([Link]() == viewBtn) {
Statement st = [Link]();
ResultSet rs = [Link]("SELECT * FROM medicine");
[Link]("ID Name Price Quantity\n");
Ignou Study Helper-Sunil Poonia Page 10
while ([Link]()) {
[Link](
[Link](1) + " " +
[Link](2) + " " +
[Link](3) + " " +
[Link](4) + "\n"
);
}
}
} catch (Exception ex) {
[Link]("Error: " + [Link]());
}
}
public static void main(String[] args) {
new MedicalStoreCRUD();
}
}
Output:
Medical Store Billing System
Medicine ID: [ ]
Name: [ ]
Price: [ ]
Quantity: [ ]
[Add] [Update] [Delete] [View]
--------------------------------
Output Area
--------------------------------
Add Record
Record Added Successfully
View Records
ID Name Price Quantity
1 Paracetamol 20.5 50
2 Crocin 15.0 30
Update Record
Record Updated Successfully
Delete Record
Record Deleted Successfully
Ignou Study Helper-Sunil Poonia Page 11