Guest User

Untitled

a guest
Dec 3rd, 2019
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Random;
  2.  
  3. class PPJ
  4. {
  5. public static void main (String[] Args)
  6. {
  7. Kwadrat kwadrat = new Kwadrat(3);
  8. kwadrat.show();
  9.  
  10. Walec walec = new Walec(2.0, 3.0);
  11. walec.show();
  12.  
  13. Osiol osiol = new Osiol(0.5);
  14.  
  15. while(!osiol.czyLata())
  16. {
  17. Balon balon = new Balon();
  18. System.out.println("Balon " + balon.podajUdzwig());
  19. osiol.dodajBalon(balon);
  20. }
  21. System.out.println("Ja latam!!!");
  22.  
  23. Wyraz wyraz = new Wyraz();
  24. wyraz.dodajZnak('a');
  25. for(int i=0;i<1000;i++)
  26. {
  27. wyraz.dodajZnak('c');
  28. }
  29.  
  30. System.out.println(wyraz.length());
  31. wyraz.wyswietl();
  32. }
  33. }
  34.  
  35. class Kwadrat
  36. {
  37. private int bok;
  38.  
  39. public Kwadrat(int bok)
  40. {
  41. this.bok = bok;
  42. }
  43.  
  44. public void show()
  45. {
  46. System.out.println("Pole: " + bok*bok + " Objetosc: " + bok*bok*bok);
  47. }
  48. }
  49.  
  50. class Walec
  51. {
  52. private double promien;
  53. private double wysokosc;
  54.  
  55. public Walec(double promien, double wysokosc)
  56. {
  57. this.promien = promien;
  58. this.wysokosc = wysokosc;
  59. }
  60.  
  61. public void show()
  62. {
  63. double ppp = promien*promien*Math.PI;
  64. System.out.println("PPP: " + ppp + " Objetosc: " + ppp*wysokosc);
  65. }
  66. }
  67.  
  68. class Balon
  69. {
  70. private double hel;
  71. private final double m3naKg = 6.0/ 1000 / 0.007;
  72.  
  73. public Balon()
  74. {
  75. Random random = new Random();
  76. hel = 0.005 + (0.009 - 0.005) * random.nextDouble();
  77. }
  78.  
  79. public double podajUdzwig()
  80. {
  81. return m3naKg * hel;
  82. }
  83. }
  84.  
  85. class Osiol
  86. {
  87. private double masa;
  88. private Balon[] balony;
  89. private int iloscBalonow;
  90. private double udzwig;
  91.  
  92. public Osiol(double masa)
  93. {
  94. this.masa = masa;
  95. balony = new Balon[(int)Math.ceil(masa/0.005)];
  96. iloscBalonow = 0;
  97. }
  98.  
  99. public void dodajBalon(Balon balon)
  100. {
  101. balony[++iloscBalonow] = balon;
  102. udzwig += balon.podajUdzwig();
  103. }
  104.  
  105. public boolean czyLata()
  106. {
  107. return udzwig > masa;
  108. }
  109. }
  110.  
  111. class Wyraz
  112. {
  113. private char[] chars;
  114. private int length;
  115.  
  116. public Wyraz()
  117. {
  118. chars = new char[100];
  119. length = 0;
  120. }
  121.  
  122. public void dodajZnak(char znak)
  123. {
  124. if(length >= chars.length)
  125. {
  126. char[] copy = new char[length+101];
  127. System.arraycopy(chars, 0, copy, 0, chars.length);
  128. chars = copy;
  129. }
  130. chars[length++] = znak;
  131. }
  132.  
  133. public void wyswietl()
  134. {
  135. for(int i=0;i<length;i++)
  136. {
  137. System.out.print(chars[i]);
  138. }
  139. }
  140.  
  141. public int length()
  142. {
  143. return length;
  144. }
  145. }
RAW Paste Data