Реализовать класс использованием интерфейсов - C#
Формулировка задачи:
Создайте консольное приложение. Реализуйте класс из задания 2 с использованием интерфейсов. Помогите с этой задачкой на си шарпе.
Вот класс из задания 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Traid : System.Object
{
protected int first, second, third, другое;
public Traid(int first, int second, int third, int другое)
{
this.first = first;
this.second = second;
this.third = third;
this.другое = 2;
}
public Traid()
{
this.first = 60;
this.second = 59;
this.third = 1;
this.другое = 4;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj)
{
Traid temp = (Traid)obj;
if (temp.first == this.first && temp.second == this.second && temp.third == this.third && temp.другое == this.другое)
{
return true;
}
else return false;
}
public virtual void Print()
{
Console.WriteLine("{0},{1},{2},{3}", first, second, third, другое);
}
}
class TIME : Traid
{
int часы;
int минуты;
int секунды;
public TIME(int часы, int минуты, int секунды, int first, int second, int third, int другое)
: base(first, second, third, другое) //конструктор базового класса
{
this.часы = часы;
this.минуты = минуты;
this.секунды = секунды;
}
public override void Print()
{
Console.WriteLine("{0}, {1}, {2}, {3}, {4}", first, second, third, часы, минуты, секунды, другое);
}
public override bool Equals(object obj)
{
TIME temp = (TIME)obj;
if (temp.часы == this.часы && temp.минуты == this.минуты && temp.секунды == this.секунды && temp.first == this.first && temp.second == this.second && temp.third == this.third && temp.другое == this.другое)
{
return true;
}
else return false;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
class Program
{
static void Main(string[] args)
{
Traid[] obj = new Traid[3];
obj[0] = new Traid();
int h, m, s, per_ch, vtor_ch, trete_ch;
Console.WriteLine("Введите часы");
h = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите минуты");
m = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите секунды");
s = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите первое число");
per_ch = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите второе число");
vtor_ch = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите третье число");
trete_ch = Convert.ToInt16(Console.ReadLine());
obj[1] = new TIME(h, m, s, per_ch, vtor_ch, trete_ch, 2);
if (!obj[0].Equals(obj[1]))
{
Console.Write("\nНе равны ");
}
Console.WriteLine("Введите часы");
int chas = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите минуты");
int min = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите секунды");
int sec = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите первое число");
int per_chislo = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите второе число");
int vtor_chislo = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Введите третье число");
int trete_chuslo = Convert.ToInt16(Console.ReadLine());
obj[2] = new TIME(chas, min, sec, per_chislo, vtor_chislo, trete_chuslo, 3);
if (obj[1].Equals(obj[1]))
{
Console.Write("\nРавны");
}
Console.ReadKey();
}
}
}Решение задачи: «Реализовать класс использованием интерфейсов»
textual
Листинг программы
public bool Equals(TIME other)
{
return other.часы == this.часы && other.минуты == this.минуты && other.секунды == this.секунды && other.first == this.first && other.second == this.second && other.third == this.third && other.другое == this.другое;
}