Реализовать перегрузку двумя способами - C#
Формулировка задачи:
Здравствуйте.
Есть следующий код:
Нужно реализовать перегрузку 2 способами:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication11
{
//Класс самолет
class Aeroplane
{
string pointName;//пункт назначения
int number; //номер рейса
DateTime time; //время вылета
public Aeroplane(string Pointname, int Number, DateTime Time)
{
pointName = Pointname;
if (Number < 100000 || Number > 999999)
throw new Exception("Номер рейса должен быть шестизначным");
number = Number;
time = Time;
}
public int Number
{
get
{
return number;
}
set
{
number = value;
}
}
public string PointName
{
get
{
return pointName;
}
set
{
pointName = value;
}
}
public DateTime TimeToFly
{
get
{
return time;
}
set
{
time = value;
}
}
}
class Aeroport
{
List<Aeroplane> planes;
public Aeroport()
{
planes = new List<Aeroplane>() ;
}
public void AddAeroplane(Aeroplane plane)
{
planes.Add(plane);
}
public void AddAeroplaneRange(params Aeroplane[] Planes)
{
planes.AddRange(Planes);
}
public void GetInforation(int index)
{
if (index > planes.Count - 1)
throw new Exception("Рейс не существует");
Console.WriteLine("Номер рейса: " + planes[index].Number);
Console.WriteLine("Пункт назначения: " + planes[index].PointName);
Console.WriteLine("Время вылета: " + planes[index].TimeToFly);
}
public void ThisHour(DateTime time)
{
DateTime time1 = new DateTime(time.Year, time.Month, time.Day, time.Hour + 1,
time.Minute, time.Second, DateTimeKind.Local);
Console.WriteLine("В течение часа вылетят самолеты:");
for (int i = 0; i < planes.Count; i++)
if (planes[i].TimeToFly > time && planes[i].TimeToFly < time1)
GetInforation(i);
Console.WriteLine("Список окончен");
}
public void TripFromPointName(string PointName)
{
Console.WriteLine("В " + PointName + " летят следующие самолеты: ");
for (int i = 0; i < planes.Count; i++)
if (planes[i].PointName == PointName)
GetInforation(i);
Console.WriteLine("Список окончен");
}
}
class Program
{
static void Main(string[] args)
{
Aeroport aeroport = new Aeroport();
Aeroplane plane = new Aeroplane("Москва", 999999, new DateTime(2011, 5, 26, 20, 0, 0, 0));
Aeroplane plane1 = new Aeroplane("Киев", 999998, new DateTime(2011, 5, 26, 20, 10, 0, 0));
Aeroplane plane2 = new Aeroplane("Минск", 999997, new DateTime(2011, 5, 26, 20, 20, 0, 0));
Aeroplane plane3 = new Aeroplane("Париж", 999996, new DateTime(2011, 5, 26, 22, 0, 0, 0));
aeroport.AddAeroplaneRange(plane, plane1, plane2, plane3);
aeroport.GetInforation(1);//информация о рейсе
aeroport.ThisHour(new DateTime(2011, 5, 26, 20, 0, 0, 0));//в течение часа
aeroport.TripFromPointName("Париж");//информация о рейсе в Париж
Console.ReadKey(true);
}
}
}1.
Используя открытые методы класса object2.
Используя стандартный интерфейс IComparableРешение задачи: «Реализовать перегрузку двумя способами»
textual
Листинг программы
class Aeroplane : IComparable<Aeroplane>
{
public int CompareTo(Aeroplane other)
{
return Number.CompareTo(other.Number);
}
public override string ToString()
{
return string.Format("Number: {0}, PointName: {1}, TimeToFly: {2}", Number, PointName, TimeToFly);
}
}