Advertisement
Levi0227

2. félév 2. hét

Feb 20th, 2024
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Rectangle rectangle = new Rectangle(120, 150, "blue");
  14.             Console.WriteLine(rectangle.ToString());
  15.             Console.ReadKey();
  16.         }
  17.     }
  18. }
  19.  
  20. -------------------------------------------------
  21. //Osztályok
  22. _________________________________________________
  23.  
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Linq;
  27. using System.Text;
  28. using System.Threading.Tasks;
  29.  
  30. namespace ConsoleApp1
  31. {
  32.     internal abstract class Shape
  33.     {
  34.         private bool isHoley;
  35.         private string color;
  36.         public string name;
  37.  
  38.         protected Shape(bool isHoley, string color)
  39.         {
  40.             this.isHoley = isHoley;
  41.             this.color = color;
  42.         }
  43.         protected Shape(string color)
  44.         {
  45.             this.color = color;
  46.             this.isHoley = false;
  47.         }
  48.  
  49.  
  50.         public string Color { get { return this.color; } set { value = this.color; } }
  51.  
  52.         public void MakeHolly()
  53.         {
  54.             this.isHoley = true;
  55.         }
  56.  
  57.         public abstract double Perimeter();
  58.         public abstract double Area();
  59.  
  60.         public override string ToString()
  61.         {
  62.             return $"{this.color} {this.isHoley} {this.Perimeter()} {this.Area()}";
  63.         }
  64.  
  65.         public override bool Equals(object obj)
  66.         {
  67.             if (obj is Shape)
  68.             {
  69.                 Shape other = obj as Shape;
  70.                 if (this.color == other.color)
  71.                 {
  72.                     return true;
  73.                 }
  74.             }
  75.             return false;
  76.         }
  77.  
  78.         public virtual void KillShape()
  79.         {
  80.             Console.WriteLine("Meghaltam!");
  81.         }
  82.     }
  83. }
  84. -------------------------------------------------
  85. using System;
  86. using System.Collections.Generic;
  87. using System.Linq;
  88. using System.Text;
  89. using System.Threading.Tasks;
  90.  
  91. namespace ConsoleApp1
  92. {
  93.     internal class Rectangle : Shape
  94.     {
  95.         public new string name;
  96.         private int height;
  97.         private int width;
  98.  
  99.         public int Height { get { return height; } set { this.height = value; } }
  100.  
  101.         public int Width { get { return width; } set { this.width = value; } }
  102.         public Rectangle(int width, int height, string color) : base(color)
  103.         {
  104.             this.height = height;
  105.             this.width = width;
  106.         }
  107.  
  108.         public Rectangle(int width, int height, bool isHoley, string color) : base(isHoley, color)
  109.         {
  110.             this.height = height;
  111.             this.width = width;
  112.         }
  113.  
  114.         public override string ToString()
  115.         {
  116.             return $"Teglalap: {base.ToString()}";
  117.         }
  118.  
  119.         public override double Area()
  120.         {
  121.             return this.width * this.height;
  122.         }
  123.  
  124.         public override double Perimeter()
  125.         {
  126.             return 2 * (this.width+this.height);
  127.         }
  128.  
  129.         public override void KillShape()
  130.         {
  131.             Console.WriteLine("Rectangle Meghalt!");
  132.         }
  133.     }
  134. }
  135.  
  136. --------------------------------------------------------
  137. using System;
  138. using System.Collections.Generic;
  139. using System.Linq;
  140. using System.Text;
  141. using System.Threading.Tasks;
  142.  
  143. namespace ConsoleApp1
  144. {
  145.     internal class Square : Shape
  146.     {
  147.         public Square(int width, int height, string color) : base(color)
  148.         {
  149.         }
  150.  
  151.         public Square(int width, int height, bool isHoley, string color) : base(isHoley, color)
  152.         {
  153.         }
  154.  
  155.         public override double Area()
  156.         {
  157.             throw new NotImplementedException();
  158.         }
  159.  
  160.         public override double Perimeter()
  161.         {
  162.             throw new NotImplementedException();
  163.         }
  164.     }
  165. }
  166.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement