Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Sprawdzenie klasy
minolone
post
Post #1





Grupa: Zarejestrowani
Postów: 141
Pomógł: 24
Dołączył: 21.06.2008

Ostrzeżenie: (0%)
-----


Witam.
Prosze was o sprawdzenie klasy oraz wyrzucenie mi wszystkich błędów co jest nie tak jak być powinno.
Jest nie skończona ale wszytsko działa tak jak chciałem.
  1. <?php
  2.  
  3. print_r($_POST);
  4.  
  5. class AirConditioning {
  6.  
  7. const HOME = 20;
  8. const HOME_ROOF = 0.2;
  9. const COMPANY = 10;
  10. const COMPANY_PERCENT = 0.1;
  11. const COMPANY_ROOF = 0.1;
  12. const PEOPLE = 0.1;
  13.  
  14. private $people;
  15. //public $window;
  16. private $roof;
  17.  
  18. public function __construct($room, $height, $area, $people, $window, $roof) {
  19. $this->room = $room;
  20. $this->height = $height;
  21. $this->area = $area;
  22. if(!empty($window)) $this->window = $window;
  23. if(!empty($people)) $this->people = $people;
  24. if(!empty($roof)) $this->roof = $roof;
  25. }
  26.  
  27. public function check() {
  28. if($this->room == 0) {
  29. return $this->home($this->height, $this->area);
  30. }
  31. if($this->room == 1) {
  32. return $this->company($this->height, $this->area);
  33. }
  34. }
  35.  
  36. public function home($height, $area) {
  37. $count = $height*$area/self::HOME;
  38.  
  39. if($this->roof == 1) {
  40. $roof = self::HOME_ROOF;
  41. }
  42.  
  43. if($this->people > 0) {
  44. $people = $this->people($this->people);
  45. }
  46.  
  47. if(isset($roof) AND $roof > 0) {
  48. $count = $count+$count*$roof;
  49. }
  50.  
  51. if(isset($people) AND $people > 0) {
  52. $count = $count+$people;
  53. }
  54.  
  55. return $count;
  56. }
  57.  
  58. public function company($height, $area) {
  59. $count = $height*$area;
  60. $count = $count/self::COMPANY;
  61. $add = self::COMPANY_PERCENT;
  62.  
  63. if($this->roof == 1) {
  64. $add += self::COMPANY_ROOF;
  65. }
  66.  
  67. if($this->people > 0) {
  68. $people = $this->people($this->people);
  69. }
  70.  
  71. if(isset($roof) AND $roof > 0) {
  72. $count = $count+$count*$roof;
  73. }
  74.  
  75. if(isset($people) AND $people > 0) {
  76. $count = $count+$people;
  77. }
  78.  
  79. return $count;
  80. }
  81.  
  82. public function people($people) {
  83. $people = $people*self::PEOPLE;
  84. return $people;
  85. }
  86.  
  87. }
  88.  
  89. ?>




Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
minolone
post
Post #2





Grupa: Zarejestrowani
Postów: 141
Pomógł: 24
Dołączył: 21.06.2008

Ostrzeżenie: (0%)
-----


Proszę o sprawdzenie poprawności kodu oraz ew. poprawki,
Napewno jakieś błędy się znajdą ale proszę o wyrozumiałość.
Ogólnie wszystko działa tak jak powinno.

  1. <?php
  2. /**
  3.  * AirConditioning
  4.  * Klasa odpowiedzialna za wyliczanie mocy klimatyzatora
  5.  */
  6. class AirConditioning {
  7. const HOME = 20; //Dzielenie wyniku m3 dla pomieszczeń mieszkalnych
  8. const HOME_ROOF = 0.2; //Dodatek 20% dla okien dachowych, mieszkalnych
  9. const COMPANY = 10; //Dzielenie wyniku m3 dla pomieszczeń handlowych
  10. const COMPANY_PERCENT = 0.1; //Dodatek 10% dla pomieszczeń handlowych
  11. const COMPANY_ROOF = 0.1; //Dodatek 10% dla okien dachowych, handlowych
  12. const PEOPLE = 0.1; //Dodatek 0.1 kW za każdego człowieka
  13. const COMPANY_SOUTH = 0.05; //Dodatek 5% za okna skierowane na południe, pomieszczenia handlowe
  14. const COMPANY_WEST = 0.05; //Dodatek 5% za okna skierowane na zachód, pomieszczenia handlowe
  15. const HOME_SOUTH = 0.1; //Dodatek 10% za okna skierowane na południe, pomieszczenia mieszkalne
  16. const HOME_WEST = 0.1; //Dodatek 10% za okna skierowane na zachód, pomieszczenia mieszkalne
  17.  
  18. public $people;
  19. public $roof;
  20. public $south;
  21. public $west;
  22.  
  23. /**
  24.   * AirConditioning::__construct()
  25.   * Pobranie danych z formularza
  26.   * @param mixed $room informacje o pomieszczeniu
  27.   * @param mixed $height wysokość pomieszzenia
  28.   * @param mixed $area powierzchnia pomieszczenia
  29.   * @param mixed $people informacje o osobach w pomieszczeniu
  30.   * @param mixed $roof okna dachowe
  31.   * @param mixed $south kierunek okien, południe
  32.   * @param mixed $west kierunek okien, zachód
  33.   */
  34. public function __construct($room, $height, $area, $people, $roof, $south, $west)
  35. {
  36. $this->room = $room;
  37. $this->height = $height;
  38. $this->area = $area;
  39.  
  40. if (!empty($north)) {
  41. $this->north = $north;
  42. }
  43.  
  44. if (!empty($south)) {
  45. $this->south = $south;
  46. }
  47.  
  48. if (!empty($east)) {
  49. $this->east = $east;
  50. }
  51.  
  52. if (!empty($west)) {
  53. $this->west = $west;
  54. }
  55.  
  56. if (!empty($people)) {
  57. $this->people = $people;
  58. }
  59.  
  60. if (!empty($roof)) {
  61. $this->roof = $roof;
  62. }
  63. }
  64.  
  65. /**
  66.   * AirConditioning::check()
  67.   * Pobranie danych o pomieszczeniu
  68.   */
  69. public function check()
  70. {
  71. if ($this->room == 1) {
  72. return $this->home($this->height, $this->area);
  73. }
  74.  
  75. if ($this->room == 2) {
  76. return $this->company($this->height, $this->area);
  77. }
  78. }
  79.  
  80. /**
  81.   * AirConditioning::home()
  82.   * Obliczanie mocy klimatyzatora dla pomieszczeń mieszkalnych
  83.   */
  84. public function home($height, $area)
  85. {
  86. $count = $height * $area / self::HOME;
  87. $add = '';
  88.  
  89. if ($this->roof == 1) {
  90. $add += self::HOME_ROOF;
  91. }
  92.  
  93. if ($this->people > 0) {
  94. $people = $this->people($this->people);
  95. }
  96.  
  97. if ($this->west == 1) {
  98. $add += self::HOME_WEST;
  99. }
  100.  
  101. if ($this->south == 1) {
  102. $add += self::HOME_SOUTH;
  103. }
  104.  
  105. $count = $count + $count * $add;
  106.  
  107. if (isset($people) and $people > 0) {
  108. $count = $count + $people;
  109. }
  110.  
  111. return $count;
  112. }
  113.  
  114. /**
  115.   * AirConditioning::company()
  116.   * Obliczanie mocy klimatyzatora dla pomieszczeń handlowych
  117.   */
  118. public function company($height, $area)
  119. {
  120. $count = $height * $area;
  121. $count = $count / self::COMPANY;
  122. $add = self::COMPANY_PERCENT;
  123.  
  124. if ($this->west == 1) {
  125. $add += self::COMPANY_WEST;
  126. }
  127.  
  128. if ($this->south == 1) {
  129. $add += self::COMPANY_SOUTH;
  130. }
  131.  
  132. if ($this->roof == 1) {
  133. $add += self::COMPANY_ROOF;
  134. }
  135.  
  136. if ($this->people > 0) {
  137. $people = $this->people($this->people);
  138. }
  139.  
  140. $count = $count + $count * $add;
  141.  
  142. if (isset($people) and $people > 0) {
  143. $count = $count + $people;
  144. }
  145.  
  146. return $count;
  147. }
  148.  
  149. /**
  150.   * AirConditioning::people()
  151.   * Wylicza moc dla każdej osoby w pomieszczeniu
  152.   */
  153. public function people($people)
  154. {
  155. $people = $this->people * self::PEOPLE;
  156.  
  157. return $people;
  158. }
  159.  
  160. }
  161.  
  162. ?>

Przykład użycia
  1. <?php
  2. $ob = new AirConditioning($room, $height, $area, $people, $roof, $north, $south, $east, $west);
  3. echo 'Wyliczone zapotrzebowanie na moc klimatyzatora wynosi '. $ob->check(). ' kW.';
  4. ?>

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 13:08