Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Hotel {
- //Class constants and variables
- private static final double ROOM_RATE = 79.95,
- TAX_RATE = 6.5,
- TELEPHONE = 5.75,
- MEAL_RATE = 12.95,
- TIP_RATE = 0.075;
- private static double totalRoom,
- totalTel,
- totalMeal,
- totalTax,
- totalTip,
- totalAmount;
- //Instance variables
- private int noOfNights, noOfGuests;
- private double amountDue, meal, tax, subTotal, total, tip;
- private String roomNumber;
- public Hotel(String room) {
- roomNumber = room;
- noOfGuests = 1;
- noOfNights = 1;
- totalRoom = totalRoom + (ROOM_RATE * noOfNights * noOfGuests);
- totalTel = totalTel + TELEPHONE;
- totalMeal = totalMeal + (MEAL_RATE * noOfNights * noOfGuests);
- totalTax = totalTax + (ROOM_RATE * noOfNights * noOfGuests) * TAX_RATE / 100;
- }
- public Hotel(String room, int nights) {
- roomNumber = room;
- noOfGuests = 1;
- noOfNights = nights;
- totalRoom = totalRoom + (ROOM_RATE * nights * noOfGuests);
- totalTel = totalTel + TELEPHONE;
- totalMeal = totalMeal + (MEAL_RATE * nights * noOfGuests);
- totalTax = totalTax + (ROOM_RATE * nights * noOfGuests) * TAX_RATE / 100;
- }
- public Hotel(String room, int nights, int guests) {
- roomNumber = room;
- noOfNights = nights;
- noOfGuests = guests;
- totalRoom = totalRoom + (ROOM_RATE * nights * guests);
- totalTel = totalTel + TELEPHONE;
- totalMeal = totalMeal + (MEAL_RATE * nights * guests);
- totalTax = totalTax + (ROOM_RATE * nights * guests) * TAX_RATE / 100;
- }
- //mutator for individual summaries
- public void calculate() {
- amountDue = ROOM_RATE * noOfNights * noOfGuests;
- tax = amountDue * (TAX_RATE / 100);
- subTotal = amountDue + tax;
- meal = MEAL_RATE * noOfNights * noOfGuests;
- tip = TIP_RATE * (subTotal + meal + TELEPHONE);
- total = subTotal + TELEPHONE + meal + tip;
- }
- //mutator for addition of more nights
- public void addNights(int nights) {
- noOfNights = noOfNights + nights;
- totalRoom = totalRoom + (ROOM_RATE * nights * noOfGuests);
- totalMeal = totalMeal + (MEAL_RATE * nights * noOfGuests);
- totalTax = totalTax + (ROOM_RATE * nights * noOfGuests) * TAX_RATE / 100;
- }
- //mutator for addition of more guests
- public void addGuest(int guests) {
- noOfGuests = noOfGuests + guests;
- totalRoom = totalRoom + (ROOM_RATE * noOfNights * guests);
- totalMeal = totalMeal + (MEAL_RATE * noOfNights * guests);
- totalTax = totalTax + (ROOM_RATE * noOfNights * guests) * TAX_RATE / 100;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement