Madhavan Mukund



Programming Language Concepts
Jan-Apr 2025

Assignment 1: Abstract classes and interfaces

3 February, 2025
Due 12 February, 2025



Task 1: Abstract class Shape

Define an abstract class Shape with concrete subclasses Circle, Square, Rectangle such that every class that inherits from Shape must redefine the following methods:

  • public double sizeOf() that returns some sensible parameter indicating the size of the object.

  • public boolean equals(Object o) based on the defining characteristics of the object rather than on pointer equality.

  • public String toString() to print out the defining characteristics of the object.


Task 2: Interface Sortable

Consider the following interface:

    public interface Sortable
       {
         public int cmp(Sortable s);  
         // return -1 if this < s,
         //         0 if this = s,
         //         1 if this > s
       }   
    
  • Java allows an interface definition to include concrete "default" methods. (Look up the documentation for Java.) Add a default method to the class Sortable that sorts arrays of type Sortable[] (use any sorting algorithm of your choice).

  • Extend the definition of Shape so that all objects that inherit from Shape are Sortable, and update the definitions of Circle, Square and Rectangle accordingly.


General instructions

  1. Submit two zip files, ABCYYYYNN-Task1.zip and ABCYYYYNN-Task2.zip, where ABCYYYYNN is your roll number. Each zip file should contain all Java source files for the corresponding task.

  2. Submissions that do not follow this naming convention will not be graded.

  3. Submissions with compilation errors will not be graded.