Java Qp
Java Qp
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
OR
Time: 3 Hours
2. Create a class called Matrix which contains a 2d integer array. Include the following
member functions
a. To read the matrix,
Time: 3 Hours
import java.io.DataInputStream;
import java.io.IOException;
class Matrix {
private int[][] matrix;
private int rows;
private int cols;
if (matrix.isSymmetric()) {
System.out.println("The matrix is symmetric.");
} else {
System.out.println("The matrix is not symmetric.");
}
}
}
Time: 3 Hours
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
Button calculateButton;
// Set layout
setLayout(new FlowLayout());
// Initialize components
add(radiusTextField);
add(calculateButton);
Time: 3 Hours
add(resultTextField);
calculateButton.addActionListener(e -> {
try {
resultTextField.setText(String.format("%.2f", area));
resultTextField.setText("Invalid Input");
});
5.Write an applet program to show how to pass a parameter from an applet code?
import java.applet.Applet;
import java.awt.Graphics;
Time: 3 Hours
String message;
message = getParameter("message");
<html>
<body>
</applet>
</body>
</html>
6.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 Exception class MarksOutOfBoundsException, If Entered marks of any
Time: 3 Hours
import java.io.DataInputStream;
import java.io.IOException;
// User-defined exception
super(message);
try {
checkMarks(subject1);
checkMarks(subject2);
checkMarks(subject3);
} catch (MarksOutOfBoundsException e) {
} catch (IOException e) {
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
Time: 3 Hours
8. Create a class called Matrix which contains a 2d integer array, m & n (order of
matrix) as data members. Include the following member functions
a. To read the matrix,
b. To display the matrix ,
c. Overload a method product () to find the product of two matrices and to
multiply each element of a matrix with a constant value
import java.io.DataInputStream;
import java.io.IOException;
class Matrix {
int m, n;
int[][] matrix;
m = Integer.parseInt(input.readLine());
n = Integer.parseInt(input.readLine());
matrix[i][j] = Integer.parseInt(input.readLine());
System.out.println("Matrix:");
System.out.println();
if (this.n != mat2.m) {
return null;
Time: 3 Hours
result.m = this.m;
result.n = mat2.n;
result.matrix[i][j] = 0;
return result;
matrix1.readMatrix();
matrix1.displayMatrix();
matrix2.readMatrix();
matrix2.displayMatrix();
if (result != null) {
matrix1.product(constant);
matrix1.displayMatrix();
9. Write a swing program to accept an integer in a textbox then reverse that number
and display the result in the second textbox?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
10. 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 both of these classes and print the
same.
import java.io.*;
class Employee {
String name, phone, address;
int age;
double salary;
try {
// Create Officer object
Officer officer = new Officer();
System.out.println("Enter Officer details:");
System.out.print("Name: ");
officer.name = dis.readLine();
System.out.print("Age: ");
officer.age = Integer.parseInt(dis.readLine());
System.out.print("Phone: ");
officer.phone = dis.readLine();
System.out.print("Address: ");
officer.address = dis.readLine();
System.out.print("Salary: ");
officer.salary = Double.parseDouble(dis.readLine());
System.out.print("Specialization: ");
officer.specialization = dis.readLine();
System.out.print("Name: ");
manager.name = dis.readLine();
System.out.print("Age: ");
manager.age = Integer.parseInt(dis.readLine());
System.out.print("Phone: ");
manager.phone = dis.readLine();
System.out.print("Address: ");
manager.address = dis.readLine();
System.out.print("Salary: ");
manager.salary = Double.parseDouble(dis.readLine());
System.out.print("Department: ");
manager.department = dis.readLine();
} catch (IOException e) {
System.out.println("Error reading input");
}
}
}