6A
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 returnThe 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
For the draft, implement the constructor and getType method. Provide stub for the getCost and setOccupants methods so that your class will compile with the tester. Provide all the Javadoc
6B
Write a class FunWithLoops that contains the methods specified below. There is no constructor or instance variables.
public int sumOdd(int value) Return the sum of all the positive odd numbers less than the given value starting with 1. If value is less than or equal to 0, return 0. Use a looppublic double average(int count) Asks the user for count integers and returns the average of the integers. If count is 5, you will prompt the user 5 times to enter a number. Use prompts that look like these in the loop:Enter integer 1: 25 Enter integer 2: 4 14.5
public double sumSeries(int value) Calculates the sum of the following series up to a value of n (n must be odd). (changed 10/10)No starter. No Javadoc
For the draft, implement the sumOdd method
6C
Complete the class LoopyText which has a constructor that takes a String of text (provided for you). Implement the following methods.
public String getEverySecondCharacter() gets a string consisting of every other character, starting with the character at index 0public int upperCaseCount() gets the number of uppercase letters in the text. You can use the String contains method or the Character class' static method isUpperCasefirstLetters that returns a string consisting of the first character of every word in the string. If the string is the empty string return the empty String. You can use indexOf (" ") to control the loop and to determine where a new word starts.Provide Javadoc
For the draft, implement the getEverySecondCharacter()method