Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. /**
  2. * Models a room at a resort
  3. */
  4. public class ResortRoom
  5. {
  6. //DEFINED CONSTANTS
  7. public static final int OCEAN_SIDE = 0;
  8. public static final int STREET_SIDE = 1;
  9. public static final int ADDITIONAL_COST_PER_PERSON=100;
  10.  
  11. //PRIVATE VARIABLES
  12. private int room;
  13. private int occupants;
  14.  
  15. //CONSTRUCTOR WITH TWO PARAMETERS
  16. /**
  17. * Provides the data of the resort room
  18. * @param type is the type of room which is either ocean or street
  19. * @param numberOfOccupants is the number of people staying in the room
  20. */
  21. public ResortRoom(int type, int numberOfOccupants)
  22. {
  23. if (type != OCEAN_SIDE && type != STREET_SIDE)
  24. {
  25. room = OCEAN_SIDE;
  26. }
  27. else
  28. {
  29. room = type;
  30. }
  31.  
  32. if (numberOfOccupants <= 0)
  33. {
  34. occupants = 2;
  35. }
  36. else
  37. {
  38. occupants = numberOfOccupants;
  39. }
  40. }
  41.  
  42. //METHODS
  43. /**
  44. * This gets the type of room
  45. * @return ocean if the room is OCEAN_SIDE or street if not
  46. */
  47. public String getType()
  48. {
  49. if (room == OCEAN_SIDE)
  50. {
  51. return "ocean";
  52. }
  53. else
  54. {
  55. return "street";
  56. }
  57. }
  58.  
  59. /**
  60. * It gets the cost of the room
  61. * @return is 0
  62. */
  63. public double getCost()
  64. {
  65. double cost=0.00;
  66. if(occupants<=2)
  67. {
  68. if(room==STREET_SIDE)
  69. {
  70. cost=175.00;
  71. }
  72. else
  73. {
  74. cost=250.00;
  75. }
  76. }
  77. else if(occupants==3||occupants==4)
  78. {
  79. if(room==STREET_SIDE)
  80. {
  81. cost=260.00;
  82. }
  83. else
  84. {
  85. cost=370.00;
  86. }
  87. }
  88.  
  89. else if (occupants>4)
  90. {
  91. int extraPeople=occupants-4;
  92. int amountToAdd=extraPeople*ADDITIONAL_COST_PER_PERSON;
  93. if(room==STREET_SIDE)
  94. {
  95. cost=amountToAdd+260.00;
  96. }
  97. else {
  98. cost=amountToAdd+370.00;
  99. }
  100. }
  101. return cost;
  102. }
  103.  
  104. /**
  105. * Gets the number of occupants in the room
  106. * @return the number of occupants in the room
  107. */
  108. public int getOccupants()
  109. {
  110. return occupants;
  111. }
  112.  
  113. /**
  114. * This sets the number of people in the room
  115. * @param number of occupants
  116. */
  117. public void setOccupants(int number)
  118. {
  119. if(number>0)
  120. {
  121. occupants=number;
  122.  
  123. }
  124. else
  125. {
  126. occupants=2;
  127.  
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement