Page 100 - CTS - CSA TP - Volume 2
P. 100
COMPUTER SOFTWARE APPLICATION - CITS
length = l;
width = w;
}
// Method to calculate area of the rectangle
double calculateArea() {
return length * width;
}
// Method to calculate perimeter of the rectangle
double calculatePerimeter() {
return 2 * (length + width);
}
}
// Main class to demonstrate the usage of Rectangle class
public class RectangleDemo {
public static void main(String[] args) {
// Create an object of Rectangle class
Rectangle rect1 = new Rectangle(5.0, 3.0);
// Accessing object properties and methods
System.out.println(“Length: “ + rect1.length);
System.out.println(“Width: “ + rect1.width);
System.out.println(“Area: “ + rect1.calculateArea());
System.out.println(“Perimeter: “ + rect1.calculatePerimeter());
}
}
Output:
85
CITS : IT & ITES - Computer Software Application - Exercise 94