From 9619d8ea8926422873d0c3559a37275af57f48b7 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 4 Dec 2022 18:13:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BAa=20=D1=81=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Catamaran/BoatCompareByColor.cs | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Catamaran/BoatCompareByColor.cs b/Catamaran/BoatCompareByColor.cs index 8d8985c..b017b93 100644 --- a/Catamaran/BoatCompareByColor.cs +++ b/Catamaran/BoatCompareByColor.cs @@ -11,8 +11,44 @@ namespace Catamaran { public int Compare(IDrawingObject x, IDrawingObject y) { - // TODO реализовать логику сравнения - throw new NotImplementedException(); + // реализовать логику сравнения + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xBoat = x as DrawingObjectBoat; + var yBoat = y as DrawingObjectBoat; + if (xBoat == null && yBoat == null) + { + return 0; + } + if (xBoat == null && yBoat != null) + { + return 1; + } + if (xBoat != null && yBoat == null) + { + return -1; + } + int colorCompare = string.Compare(xBoat.GetBoat.Catamaran.BodyColor.Name, yBoat.GetBoat.Catamaran.BodyColor.Name); + if (colorCompare != 0) + { + return colorCompare; + } + var speedCompare = xBoat.GetBoat.Catamaran.Speed.CompareTo(yBoat.GetBoat.Catamaran.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xBoat.GetBoat.Catamaran.Weight.CompareTo(yBoat.GetBoat.Catamaran.Weight); } } }