Skip to content

Commit bda9187

Browse files
committed
x
1 parent 0915e79 commit bda9187

File tree

7 files changed

+104
-6
lines changed

7 files changed

+104
-6
lines changed

src/Library/Circle.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
using System;
3+
4+
namespace Ucu.Poo.Shapes
5+
{
6+
7+
public class Circle : Elementos
8+
{
9+
public double Radius { get; set; }
10+
public string Type { get; set; } = "circle";
11+
12+
public double CalculatePerimeter()
13+
{
14+
15+
return 2 * Math.PI * Radius;
16+
}
17+
18+
public double CalculateArea()
19+
{
20+
21+
return Math.PI * Radius * Radius;
22+
}
23+
}
24+
}

src/Library/Elementos.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Ucu.Poo.Shapes
2+
{
3+
public class Elementos
4+
{
5+
public int id {get; set;}
6+
}
7+
}

src/Library/IPrintable.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Ucu.Poo.Shapes
2+
{
3+
public interface IPrintable
4+
{
5+
void Print(Elementos elementos);
6+
}
7+
}

src/Library/Print.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Text.Json;
3+
4+
namespace Ucu.Poo.Shapes
5+
{
6+
public class ConsolePrinter : IPrintable
7+
{
8+
public void Print(Elementos elementos)
9+
{
10+
string json = JsonSerializer.Serialize(elementos, elementos.GetType());
11+
12+
Console.WriteLine(json);
13+
}
14+
}
15+
}

src/Library/Square.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22

33
namespace Ucu.Poo.Shapes
44
{
5-
public class Circle
5+
public class Square : Elementos
66
{
7-
7+
public double Side { get; set; }
8+
public int Area { get; set; }
9+
public int Perimeter { get; set; }
10+
public string Type { get; set; } = "square";
11+
12+
public double CalculateArea()
13+
{
14+
return this.Side * this.Side;
15+
}
16+
17+
public double CalculatePerimeter()
18+
{
19+
return this.Side * 4;
20+
}
821
}
922
}

src/Library/Triangle.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Ucu.Poo.Shapes
2+
{
3+
public class Triangle : Elementos
4+
{
5+
public double Side1 { get; set; }
6+
public double Side2 { get; set; }
7+
public double Side3 { get; set; }
8+
public string Type { get; set; } = "triangle";
9+
10+
11+
public double CalculatePerimeter()
12+
{
13+
return this.Side1 + this.Side2 + this.Side3;
14+
}
15+
16+
public double CalculateArea()
17+
{
18+
19+
double s = (this.Side1 + this.Side2 + this.Side3) / 2;
20+
return s;
21+
}
22+
}
23+
}

src/Program/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
using System;
2-
3-
namespace Ucu.Poo.Shapes
2+
using Ucu.Poo.Shapes;
3+
namespace Program
44
{
5-
public static class Program
5+
class Program
66
{
7-
public static void Main()
7+
static void Main(string[] args)
88
{
9+
10+
Square square = new Square();
11+
square.id = 12;
12+
square.Side = 5.2;
13+
ConsolePrinter printer = new ConsolePrinter();
14+
15+
printer.Print(square);
16+
17+
918
}
1019
}
1120
}

0 commit comments

Comments
 (0)