Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Models a room at a resort
- */
- public class ResortRoom
- {
- //DEFINED CONSTANTS
- public static final int OCEAN_SIDE = 0;
- public static final int STREET_SIDE = 1;
- public static final int ADDITIONAL_COST_PER_PERSON=100;
- //PRIVATE VARIABLES
- private int room;
- private int occupants;
- //CONSTRUCTOR WITH TWO PARAMETERS
- /**
- * Provides the data of the resort room
- * @param type is the type of room which is either ocean or street
- * @param numberOfOccupants is the number of people staying in the room
- */
- public ResortRoom(int type, int numberOfOccupants)
- {
- if (type != OCEAN_SIDE && type != STREET_SIDE)
- {
- room = OCEAN_SIDE;
- }
- else
- {
- room = type;
- }
- if (numberOfOccupants <= 0)
- {
- occupants = 2;
- }
- else
- {
- occupants = numberOfOccupants;
- }
- }
- //METHODS
- /**
- * This gets the type of room
- * @return ocean if the room is OCEAN_SIDE or street if not
- */
- public String getType()
- {
- if (room == OCEAN_SIDE)
- {
- return "ocean";
- }
- else
- {
- return "street";
- }
- }
- /**
- * It gets the cost of the room
- * @return is 0
- */
- public double getCost()
- {
- double cost=0.00;
- if(occupants<=2)
- {
- if(room==STREET_SIDE)
- {
- cost=175.00;
- }
- else
- {
- cost=250.00;
- }
- }
- else if(occupants==3||occupants==4)
- {
- if(room==STREET_SIDE)
- {
- cost=260.00;
- }
- else
- {
- cost=370.00;
- }
- }
- else if (occupants>4)
- {
- int extraPeople=occupants-4;
- int amountToAdd=extraPeople*ADDITIONAL_COST_PER_PERSON;
- if(room==STREET_SIDE)
- {
- cost=amountToAdd+260.00;
- }
- else {
- cost=amountToAdd+370.00;
- }
- }
- return cost;
- }
- /**
- * Gets the number of occupants in the room
- * @return the number of occupants in the room
- */
- public int getOccupants()
- {
- return occupants;
- }
- /**
- * This sets the number of people in the room
- * @param number of occupants
- */
- public void setOccupants(int number)
- {
- if(number>0)
- {
- occupants=number;
- }
- else
- {
- occupants=2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement