Page 110 - CTS - CSA TP - Volume 2
P. 110
COMPUTER SOFTWARE APPLICATION - CITS
}
// Method to display employee details
public static void displayEmployeeDetails(Employee employee) {
System.out.println(“Employee Details:”);
System.out.println(“Name: “ + employee.name);
System.out.println(“Salary: “ + employee.salary);
}
}
Output:
Explanation:
• This program defines a class Employee with name and salary attributes.
• We create an object employee of the Employee class and initialize it with name and salary values.
• We define a method displayEmployeeDetails that takes an Employee object as a parameter and displays its
details.
• In the main method, we call the displayEmployeeDetails method and pass the employee object as an argument.
TASK 2: Calculating Area and Perimeter of a Rectangle
class Rectangle {
double length;
double width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
// Method to calculate the area of the rectangle
double calculateArea() {
return length * width;
95
CITS : IT & ITES - Computer Software Application - Exercise 95