Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
2
Indexable
Never
using System;
using System.Collections.Generic;

public interface IShape
{
    double Area()
    {
        return 0;
    }
}

public class Rectangle : IShape
{
    public double Length { get; set; }
    public double Width { get; set; }

    public double Area()
    {
        return Length * Width;
    }
}

public class Trapezoid : IShape
{
    public double Length1 { get; set; }
    public double Length2 { get; set; }
    public double Width { get; set; }

    public double Area()
    {
        return (Length1 + Length2) * Width / 2;
    }
}

public class Room<T> where T : IShape
{
    public double Height { get; set; }
    public T Floor { get; set; }

    public double Volume()
    {
        return Floor.Area() * Height;
    }
}

public class RoomComparerByVolume<T> : IComparer<Room<T>> where T : IShape
{
    public int Compare(Room<T> room1, Room<T> room2)
    {
        double volume1 = room1.Volume();
        double volume2 = room2.Volume();

        if (volume1 < volume2)
            return -1;
        else if (volume1 > volume2)
            return 1;
        else
            return 0;
    }
}