Assignment 1-1
Assignment 1-1
Dr. F. J. Kiwa
Assignment 1
Group of 10 people
1. Inheritance and Polymorphism
∙ Create a base class called Shape with a method getArea() that returns -1.
∙ Create two derived classes, Circle and Rectangle. Override the getArea() method in both to
compute the area based on the class's specific properties.
Challenge: Use a Shape[] array to store objects of Circle and Rectangle. Calculate and print
the total area of all shapes in the array.
∙ Ensure the classes provide appropriate implementations for the performFunction() method.
Question: Why might it be better to use an interface for Device rather than a class?
Create a class ImmutablePoint representing a point in a 2D plane. Ensure the class is immutable by:
∙ If the withdrawal amount exceeds the current balance, throw the InvalidBalanceException.
Task: Write a program to test the exception handling and explain why custom exceptions are
useful.