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

COMPUTER SOFTWARE APPLICATION - CITS





           •  Run the program:




           Output:
















           This example demonstrates how to use multiple classes in a package, keeping related functionality organized.
           Related Exersises
           1   Create and use virtual methods.

              •  Question: Create a base class Shape with a virtual method calculateArea(). Create derived classes Circle
                 and Rectangle implementing this method to calculate the area of a circle and rectangle, respectively.
           2    Create abstract classes and methods.

              •  Question: Define an abstract class Bank with an abstract method calculateInterest(). Create subclasses
                 SavingsAccount and FixedDeposit to implement this method for calculating interest.
           3   Create interfaces in JAVA.

              •  Question:  Define  an  interface  Drawable  with  a  method  draw().  Create  classes  Circle  and  Square
                 implementing this interface to provide their own implementations of drawing.
           4   Override methods in JAVA.
              •  Question: Create a base class Animal with a method makeSound(). Create subclasses Dog and Cat that
                 override this method to make different sounds.
           5   Create and implement an interface.
              •  Question: Define an interface Resizable with a method resize(int percentage). Implement this interface in
                 a class ResizableRectangle that adjusts its dimensions based on the percentage.
           6   Extend interfaces in JAVA.
              •  Question: Create an interface AdvancedDrawable extending the Drawable interface with a method rotate().
                 Implement this interface in a class RotatableSquare.
           7   Create and use a package in JAVA.
              •  Question: Create a package named utilities and include a class Calculator with methods for addition,
                 subtraction, multiplication,  and division. Use this package in a  Main class to  perform basic arithmetic
                 operations.

















                                                           187
 CITS : IT & ITES - Computer Software Application - Exercise 115  CITS : IT & ITES - Computer Software Application - Exercise 115
   197   198   199   200   201   202   203   204   205   206   207