Advertisement
Guest User

Class file

a guest
Jun 17th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Hotel {
  2.  
  3. //Class constants and variables
  4. private static final double ROOM_RATE = 79.95,
  5. TAX_RATE = 6.5,
  6. TELEPHONE = 5.75,
  7. MEAL_RATE = 12.95,
  8. TIP_RATE = 0.075;
  9. private static double totalRoom,
  10. totalTel,
  11. totalMeal,
  12. totalTax,
  13. totalTip,
  14. totalAmount;
  15. //Instance variables
  16. private int noOfNights, noOfGuests;
  17. private double amountDue, meal, tax, subTotal, total, tip;
  18. private String roomNumber;
  19.  
  20. public Hotel(String room) {
  21. roomNumber = room;
  22. noOfGuests = 1;
  23. noOfNights = 1;
  24. totalRoom = totalRoom + (ROOM_RATE * noOfNights * noOfGuests);
  25. totalTel = totalTel + TELEPHONE;
  26. totalMeal = totalMeal + (MEAL_RATE * noOfNights * noOfGuests);
  27. totalTax = totalTax + (ROOM_RATE * noOfNights * noOfGuests) * TAX_RATE / 100;
  28. }
  29.  
  30. public Hotel(String room, int nights) {
  31. roomNumber = room;
  32. noOfGuests = 1;
  33. noOfNights = nights;
  34. totalRoom = totalRoom + (ROOM_RATE * nights * noOfGuests);
  35. totalTel = totalTel + TELEPHONE;
  36. totalMeal = totalMeal + (MEAL_RATE * nights * noOfGuests);
  37. totalTax = totalTax + (ROOM_RATE * nights * noOfGuests) * TAX_RATE / 100;
  38. }
  39.  
  40. public Hotel(String room, int nights, int guests) {
  41. roomNumber = room;
  42. noOfNights = nights;
  43. noOfGuests = guests;
  44. totalRoom = totalRoom + (ROOM_RATE * nights * guests);
  45. totalTel = totalTel + TELEPHONE;
  46. totalMeal = totalMeal + (MEAL_RATE * nights * guests);
  47. totalTax = totalTax + (ROOM_RATE * nights * guests) * TAX_RATE / 100;
  48. }
  49.  
  50. //mutator for individual summaries
  51. public void calculate() {
  52. amountDue = ROOM_RATE * noOfNights * noOfGuests;
  53. tax = amountDue * (TAX_RATE / 100);
  54. subTotal = amountDue + tax;
  55. meal = MEAL_RATE * noOfNights * noOfGuests;
  56. tip = TIP_RATE * (subTotal + meal + TELEPHONE);
  57. total = subTotal + TELEPHONE + meal + tip;
  58.  
  59. }
  60.  
  61. //mutator for addition of more nights
  62. public void addNights(int nights) {
  63. noOfNights = noOfNights + nights;
  64. totalRoom = totalRoom + (ROOM_RATE * nights * noOfGuests);
  65. totalMeal = totalMeal + (MEAL_RATE * nights * noOfGuests);
  66. totalTax = totalTax + (ROOM_RATE * nights * noOfGuests) * TAX_RATE / 100;
  67. }
  68. //mutator for addition of more guests
  69. public void addGuest(int guests) {
  70. noOfGuests = noOfGuests + guests;
  71. totalRoom = totalRoom + (ROOM_RATE * noOfNights * guests);
  72. totalMeal = totalMeal + (MEAL_RATE * noOfNights * guests);
  73. totalTax = totalTax + (ROOM_RATE * noOfNights * guests) * TAX_RATE / 100;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement