Advertisement
Guest User

Untitled

a guest
Jan 14th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 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 Program10._1
  8. {
  9. abstract class Statek
  10. {
  11. protected static int licznik = 0;
  12. protected int numerStatku;
  13. protected string typ;
  14. protected double predkoscMax;
  15.  
  16. public abstract int oblicz_zanurzenie();
  17. public void info_ogolne()
  18. {
  19. Console.WriteLine("Numer Statku Typ Statku Prędkość Maksymalna");
  20. Console.Write(" {0:D3}", numerStatku);
  21. Console.Write(" " + typ + " ");
  22. Console.WriteLine(" {0:F2}", predkoscMax);
  23. }
  24. }
  25.  
  26. class Jacht : Statek
  27. {
  28. int dlugosc;
  29. double powZagli;
  30.  
  31. Jacht(string t, double pM, int d, double pZ)
  32. {
  33. Console.WriteLine("Konstruktor klasy Jacht o 4 argumentach");
  34. numerStatku = licznik++;
  35. typ = t;
  36. predkoscMax = pM;
  37. dlugosc = d;
  38. powZagli = pZ;
  39. }
  40. public override int oblicz_zanurzenie()
  41. {
  42. int a;
  43. a = (int)(predkoscMax * 100 / (3 * dlugosc));
  44. return a;
  45. }
  46. public void info_jachtu()
  47. {
  48. Console.WriteLine("Długość jachtu: {0:F2} metrów", dlugosc);
  49. Console.WriteLine("Zanurzenie: {0} centymetrów", oblicz_zanurzenie());
  50. }
  51. public static void Main()
  52. {
  53. Jacht jolka = new Jacht("Rybka", 6.7, 4, 10.5);
  54. jolka.info_ogolne();
  55. jolka.info_jachtu();
  56.  
  57. JachtPelnomorski jp = new JachtPelnomorski("Drowning Daisy", 10, 6, 12);
  58. jp.info_ogolne();
  59. jp.info_jachtu();
  60. jp.Bar();
  61.  
  62. Console.ReadLine();
  63. }
  64. }
  65.  
  66. public sealed class JachtPelnomorski : Jacht
  67. {
  68. // Wlasne pole
  69. int foo = 5;
  70.  
  71. JachtPelnomorski(string t, double pM, int d, double pZ)
  72. {
  73. base(t, pM, d, pZ);
  74. Console.WriteLine("Konstruktor klasy JachtPelnomorski o 4 argumentach");
  75. }
  76.  
  77. // Wlasna metoda
  78. public void Bar()
  79. {
  80. Console.WriteLine("JachtPelnomorski::Bar foo={0}", foo);
  81. }
  82.  
  83. // Inna metoda na zanurzenie.
  84. public override int oblicz_zanurzenie()
  85. {
  86. return (int)(predkoscMax * 50 / (3 * dlugosc));
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement