File tree Expand file tree Collapse file tree 7 files changed +104
-6
lines changed
Expand file tree Collapse file tree 7 files changed +104
-6
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ namespace Ucu . Poo . Shapes
2+ {
3+ public class Elementos
4+ {
5+ public int id { get ; set ; }
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ namespace Ucu . Poo . Shapes
2+ {
3+ public interface IPrintable
4+ {
5+ void Print ( Elementos elementos ) ;
6+ }
7+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 22
33namespace 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11using 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}
You can’t perform that action at this time.
0 commit comments