Untitled
unknown
plain_text
a year ago
1.7 kB
3
Indexable
Never
using System; using System.Collections.Generic; using System.Reflection.Metadata.Ecma335; 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> : ICloneable, IComparable<Room<T>> where T : IShape, ICloneable { public double Height { get; set; } public T Floor { get; set; } public double Volume() { return Floor.Area() * Height; } // ICloneable public object Clone() { Room<T> clone = new Room<T>(); clone.Height = Height; clone.Floor = Floor; return clone; } //I public int CompareTo(Room<T> other) { double thisFloorArea = Floor.Area(); double otherFloorArea = other.Floor.Area(); if (thisFloorArea < otherFloorArea) return -1; else if (thisFloorArea > otherFloorArea) return 1; else return 0; } } public class RoomComparerByVolume<T> : IComparer<Room<T>> where T : IShape, ICloneable { 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; } }