Advertisement
Guest User

adapter

a guest
Nov 12th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WzorceProjektowe
  4. {
  5.     // Nie zmieniaj poniższego interfejsu
  6.     public interface IRectangle
  7.     {
  8.         int Area();
  9.         int GetWidth();
  10.         int GetHeight();
  11.     }
  12.     // Nie zmieniaj poniższej klasy
  13.     public class Rectangle : IRectangle
  14.     {
  15.         int Height;
  16.         int Width;
  17.         public Rectangle(int height, int width)
  18.         {
  19.             Height = height;
  20.             Width = width;
  21.         }
  22.         public int Area()
  23.         {
  24.             return Width * Height;
  25.         }
  26.         public int GetHeight()
  27.         {
  28.             return Height;
  29.         }
  30.         public int GetWidth()
  31.         {
  32.             return Width;
  33.         }
  34.     }
  35.     // Nie zmieniaj poniższej klasy
  36.     public class Square
  37.     {
  38.         int Side;
  39.         public Square(int side)
  40.         {
  41.             Side = side;
  42.         }
  43.         public int Area()
  44.         {
  45.             return Side * Side;
  46.         }
  47.         public int GetSide()
  48.         {
  49.             return Side;
  50.         }
  51.     }
  52.  
  53.     public class SquareToRectangleAdapter
  54.     {
  55.       // TODO
  56.     }
  57.     // Nie zmieniaj poniższej klasy
  58.     public class Program
  59.     {
  60.         static void Main(string[] args)
  61.         {
  62.             Square kwadrat = new Square(4);
  63.             IRectangle adapter = new SquareToRectangleAdapter(kwadrat);
  64.             Console.WriteLine($"Prostokąt o bokach a={adapter.GetHeight()} i b={adapter.GetWidth()} ma pole {adapter.Area()} ");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement