Guest User

Untitled

a guest
Aug 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?
  2.  
  3. // membuat kelas dengan user
  4. class User {
  5.  
  6. //property
  7. public $nama;
  8. public $ttl;
  9. public $jk;
  10. public $alamat;
  11. public $pekerjaan;
  12. public $hobi;
  13. public $goldarah;
  14.  
  15. // membuat method
  16. function setNama( $name ) {
  17. $this->nama = $name;
  18. return;
  19. }
  20.  
  21. function getNama() {
  22. return $this->nama;
  23. }
  24.  
  25. function setTtl( $tempat ) {
  26. $this->ttl = $tempat;
  27. return;
  28. }
  29.  
  30. function getTtl() {
  31. return $this->ttl;
  32. }
  33.  
  34. function setJk( $jk ) {
  35. $this->jk = $jk;
  36. return;
  37. }
  38.  
  39. function getJk() {
  40. return $this->jk;
  41. }
  42.  
  43.  
  44. function setAlamat( $Alamat ) {
  45. $this->alamat = $Alamat;
  46. return;
  47. }
  48.  
  49. function getAlamat() {
  50. return $this->alamat;
  51. }
  52.  
  53. function setPekerjaan( $pekerjaan ) {
  54. $this->pekerjaan = $pekerjaan;
  55. return;
  56. }
  57.  
  58. function getPekerjaan() {
  59. return $this->pekerjaan;
  60. }
  61.  
  62. function setHobi( $hobi ) {
  63. $this->hobi = $hobi;
  64. return;
  65. }
  66.  
  67. function getHobi() {
  68. return $this->hobi;
  69. }
  70.  
  71. function setGd( $Goldarah ) {
  72. $this->goldarah = $Goldarah;
  73. return;
  74. }
  75.  
  76. function getGd() {
  77. return $this->goldarah;
  78. }
  79.  
  80.  
  81. }
  82.  
  83. /* membuat object */
  84. $datadiri = new User;
  85.  
  86. /* memanggil object methods */
  87. $datadiri->setNama( 'Cristofel Recky' );
  88. $datadiri->setTtl( 'JAKARTA / 10-11-1990' );
  89. $datadiri->setJk( 'Laki - Laki' );
  90. $datadiri->setAlamat( 'JAKARTA' );
  91. $datadiri->setPekerjaan( 'MAHASISWA' );
  92. $datadiri->setHobi( 'Olahraga' );
  93. $datadiri->setGd( 'A' );
  94. echo "Nama : ".$datadiri->getNama().'<br />';
  95. echo "TTL : ".$datadiri->getTtl().'<br />';
  96. echo "Jenis Kelamin : ".$datadiri->getJk().'<br />';
  97. echo "Alamat : ".$datadiri->getAlamat().'<br />';
  98. echo "Pekerjaan : ".$datadiri->getPekerjaan().'<br />';
  99. echo "Hobi : ".$datadiri->getHobi().'<br />';
  100. echo "Golongan Darah : ".$datadiri->getGd().'<br />';
  101. ?>
Add Comment
Please, Sign In to add comment