Practical With Solution
Practical With Solution
Max Marks: 80 (Q1: 25 marks, Q2: 35 marks, Record: 10 marks, Viva: 10 Marks)
SET 1
1. Write an applet program to display a traffic light.
2. Create a class called Matrix which contains a 2d integer array. Include the following member
functions
c. check whether the given matrix is symmetric or not. (Solution @ end of the page)
SET 2
1. Write a swing program to accept a value in a textbox then find the area of a circle and
2. Write multithreaded program to print lowercase letters and uppercase letters from two
SET 3
1. Write an applet program to show how to pass a parameter from an applet code?
2. Write a Java Program to calculate the Result. Result should consist of name, seatno,
date, center number and marks of semester three exam. Create a User Defined
greater than 100 or less than 0, and then program should create a user defined
Exception of type.
SET4
1. Write an applet program to draw a house
2. Create a class called Matrix which contains a 2d integer array, m & n (order of matrix)
SET5
1. Write a swing program to accept an integer in a textbox then reverse that number and
2 Write a Java program which creates a class named 'Employee' having the following
members: Name, Age, Phone number, Address, Salary. It also has a method named
'printSalary( )' which prints the salary of the Employee. Two classes 'Officer' and
'Manager' inherits the 'Employee' class. The 'Officer' and 'Manager' classes have
data members 'specialization' and 'department' respectively. Now, assign name, age,
phone number, address and salary to an officer and a manager by making an object of
SET6
SET7
SET8
SET9
SET10
SET
SET SET
SET
SET
SET
SET 1 SOLUTION
write java program to Create a class called Matrix which contains a 2d integer array. Include the following
member functions
Here is the Java program implementing the Matrix class with the required functionalities:
import java.util.Scanner;
this.rows = rows;
this.cols = cols;
matrix[i][j] = scanner.nextInt();
System.out.println();
if (rows != cols) {
return false;
}
if (matrix[i][j] != matrix[j][i]) {
return false;
return true;
mat.readMatrix();
mat.displayMatrix();
if (mat.isSymmetric()) {
} else {
scanner.close();
1. Class Members:
2. Constructor:
o Initializes the matrix dimensions and allocates memory for the 2D array.
3. Methods:
o isSymmetric(): Checks if the matrix is square and whether matrix[i][j] equals matrix[j][i].
4. Main Method:
o Reads matrix dimensions, creates a Matrix object, and invokes the methods to read,
display, and check symmetry.
Sample Output:
Enter the number of rows: 3
Element [0][0]: 1
Element [0][1]: 2
Element [0][2]: 3
Element [1][0]: 2
Element [1][1]: 4
Element [1][2]: 5
Element [2][0]: 3
Element [2][1]: 5
Element [2][2]: 6
123
245
356
which are the similar functions used like .isSymmetric() in 2 dimensional arrays
In 2D arrays, functions similar to .isSymmetric() often involve analyzing or transforming the matrix based
on its structure, properties, or elements. Here are some examples of similar utility functions and their
purposes:
1. isSquare()
Purpose: Check if the given matrix is a square matrix (i.e., rows = columns).
2. isDiagonal()
Purpose: Check if the matrix is a diagonal matrix (non-diagonal elements are zero).
if (i != j && matrix[i][j] != 0) {
return false;
return true;
3. isIdentity()
Purpose: Check if the matrix is an identity matrix (diagonal elements are 1, others are 0).
return true;
4. isUpperTriangular()
Purpose: Check if the matrix is upper triangular (all elements below the main diagonal are zero).
if (matrix[i][j] != 0) {
return false;
return true;
5. isLowerTriangular()
Purpose: Check if the matrix is lower triangular (all elements above the main diagonal are zero).
if (matrix[i][j] != 0) {
return false;
return true;
6. transpose()
transposed.matrix[j][i] = this.matrix[i][j];
return transposed;
7. isSkewSymmetric()
Purpose: Check if the matrix is skew-symmetric (transpose equals the negative of the matrix).
public boolean isSkewSymmetric() {
if (matrix[i][j] != -matrix[j][i]) {
return false;
return true;
8. isEqual(Matrix other)
if (this.matrix[i][j] != other.matrix[i][j]) {
return false;
}
return true;
9. getTrace()
int trace = 0;
trace += matrix[i][i];
return trace;
10. isZeroMatrix()
if (matrix[i][j] != 0) {
return false;
}
return true;
These utility methods can help analyze and manipulate 2D matrices in various ways, allowing for greater
flexibility in working with mathematical and logical operations in matrix processing.