-
Notifications
You must be signed in to change notification settings - Fork 5
/
Shape (2).cs
52 lines (45 loc) · 1.24 KB
/
Shape (2).cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using System.Runtime.Serialization.Json;
namespace Homework8
{
[DataContract]
[Serializable]
public abstract class Shape: IComparable<Shape>
{
private string name;
[DataMember]
[XmlAttribute]
public string Name { get { return name; } set { name = value; } }
public Shape() { }
public Shape(string name)
{
this.name = name;
}
abstract public double Area();
abstract public double Perimeter();
public override string ToString()
{
return new string($"Name: {name}");
}
public void PrintToFile(StreamWriter stream)
{
stream.WriteLine($"Name: {name}");
}
public int CompareTo([AllowNull] Shape other)
{
if (this.Area() > other.Area())
{ return 1; }
else if (this.Area() < other.Area())
{ return -1; }
else
return 0;
}
}
}