Page 105 - CTS - CSA TP - Volume 2
P. 105

COMPUTER SOFTWARE APPLICATION - CITS





           Output :



















           Explanation:

           •  This program defines a Car class with properties like make, model, and year.
           •  It has a constructor to initialize the instance variables.
           •  The displayInfo() method prints out the car’s information.
           •  In the main() method, an object myCar of the Car class is created and its properties are accessed using the
              displayInfo() method.



           TASK 5: Circle Class

              class Circle {
                  // Instance variable
                  double radius;
                  // Constructor

                  Circle(double r) {
                      radius = r;
                  }
                  // Method to calculate area
                  double calculateArea() {

                      return Math.PI * radius * radius;
                  }
                  // Method to calculate circumference
                  double calculateCircumference() {

                      return 2 * Math.PI * radius;
                  }
              }
              public class CircleDemo {
                  public static void main(String[] args) {
                      // Create an object of Circle class







                                                           90

                               CITS : IT & ITES - Computer Software Application - Exercise 94
   100   101   102   103   104   105   106   107   108   109   110