Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 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 ConsoleApplication2
  8. {
  9. class Punkt {
  10. int x;
  11. int y;
  12.  
  13. public Punkt(int x, int y) {
  14. this.x = x;
  15. this.y = y;
  16. }
  17. public void Przesuń(int a, int b) {
  18. this.x += a;
  19. this.y += b;
  20. }
  21. public bool CzyIdentyczny(Punkt p)
  22. {
  23. return x == p.x && y == p.y;
  24. }
  25. public void Wyświetl() {
  26. Console.WriteLine("X: "+x+ " Y: "+y);
  27. }
  28. }
  29.  
  30. class PunktKolorowy : Punkt {
  31. string kolor;
  32.  
  33. public PunktKolorowy(int x, int y, string kolor)
  34. : base(x, y)
  35. {
  36. this.kolor = kolor;
  37. }
  38. public new void Wyświetl()
  39. {
  40. base.Wyświetl();
  41. Console.WriteLine("Kolor: "+kolor);
  42. }
  43.  
  44. public bool CzyIdentyczny(PunktKolorowy p)
  45. {
  46. return kolor == p.kolor && base.CzyIdentyczny(p);
  47. }
  48. }
  49.  
  50. class PunktKolorowyOpisowy : PunktKolorowy
  51. {
  52. string opis;
  53.  
  54. public PunktKolorowyOpisowy(int x, int y, string kolor, string opis) : base(x, y, kolor)
  55. {
  56. this.opis = opis;
  57. }
  58.  
  59. public void Wyświetl()
  60. {
  61. Console.WriteLine("Opis: " + opis);
  62. base.Wyświetl();
  63. }
  64.  
  65. }
  66.  
  67. class Program
  68. {
  69. static void Main(string[] args) {
  70. Punkt p = new Punkt(3, 4);
  71. p.Wyświetl();
  72.  
  73. p.Przesuń(1, 1);
  74. p.Wyświetl();
  75.  
  76. PunktKolorowy p2 = new PunktKolorowy(1, 2, "czarny");
  77. p2.Wyświetl();
  78.  
  79. Console.ReadKey();
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement