Question: Java: The Java Beach Resort has two types of rooms: Ocean Side and Street Side. The price is based on the number of occupants and

Java:

The Java Beach Resort has two types of rooms: Ocean Side and Street Side. The price is based on the number of occupants and the type. See the table. Complete the class ResortRoom.

2 people 4 people
Ocean side $250.00 $370.00
Street side $175.00 $260.00

An int is used to represent the type of view. 0 is ocean view and 1 is street side. Use the defined constants to avoid errors

public static final int OCEAN_SIDE = 0;

public static final int STREET_SIDE = 1;

ResortRoom has a constructor that takes two parameters.

public ResortRoom(int type, int numberOfOccupants)

If type is other than OCEAN_SIDE or STREET_SIDE, set the type to OCEAN_SIDE.

If the number of occupants is <= 0, set the occupants to 2.

Call the instance variable for the number of occupants occupants. That way the provided getOccupants method will work.

It also has a methods:

public double getCost() - gets the cost of the specified room. Use nested if statements.

public int getOccupants() gets the number of occupants in the room (provided)

public void setOccupants(int number) - sets the number of occupants renting this ResortRoom

public String getType() - gets type of this room, either "ocean" or "street" You will need to use an if statement to determine which string to return

The cost is based on the table above. One person costs the same as two people and three people cost the same as 4 people. For more than 4 people, the charge is $100 per each additional person for any room.

Define and use a constant for the cost for an extra person. (What should data type should it be?)

Provide Javadoc

Use the following file:

ResortRoomTester.java

/** * Tester for ResortRoom * @author Kathleen O'Brien */ public class ResortRoomTester { public static void main(String[]args) { ResortRoom room = new ResortRoom(ResortRoom.OCEAN_SIDE, 2); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: ocean 2 250.0"); room.setOccupants(1); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: ocean 1 250.0"); room.setOccupants(0); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: ocean 2 250.0"); room = new ResortRoom(ResortRoom.OCEAN_SIDE, 4); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: ocean 4 370.0"); room.setOccupants(6); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: ocean 6 570.0"); //test bad type room = new ResortRoom(3, 3); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: ocean 3 370.0"); room = new ResortRoom(ResortRoom.STREET_SIDE, 2); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: street 2 175.0"); room.setOccupants(1); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: street 1 175.0"); room = new ResortRoom(ResortRoom.STREET_SIDE, 3); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: street 3 260.0"); room = new ResortRoom(ResortRoom.STREET_SIDE, 5); System.out.println(room.getType() + " " + room.getOccupants() + " " + room.getCost()); System.out.println("Expected: street 5 360.0"); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!