6A
Santa Cruz Inn rents rooms. The price per night varies depending on the season of the year (low and high) and the number of people in the room. Below is a table of prices. Add $50.50 for every person over 4.
2 people | 4 people | |
---|---|---|
high season | $250 | $375 |
low season | $200 | $300 |
Complete the class SantaCruzInnRoom
which models a room at this motel.
It will have a constructor that takes the season and the number of people in that order
public SantaCruzInnRoom(String season, int numberOfGuests)
It has methods:
public String getSeason
() Gets the season (provided)public int getGuests()
gets the number of people in the room (provided)public void setGuests(int numberOfGuests)
Set the number of people in the room. (Be sure to do error checking here)public double getCost()
Gets the cost of this roomThe 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 a flat $50.50 per extra person in either season. Use nested if statements. Only use 1 return statement. Use the constant provided.
Provide Javadoc
For the draft, provide the constructor and the implementation of setGuests
method. Code getCost
as a stub. The instance varibles are provided along with the getSeason
and getGuests
methods
6B
Create a class LoopsAndMore
. It has several methods that use loops. There are no instance variables. These problems aren't especially useful, but they will let you practice writing loops.
public int sumEveryThird(int limit)
gets the sum of every third number that is less than a given limit starting with 3 - EXCEPT those divisible by 5. Use a loop in the final. (You will not need a loop in the draft.) If the limit is 21, you would calculatepublic String printJava(int count)
gets a string that contains Java count times all on one line, separated by spaces. You must use a loop. The output for countJava(5) will look like this: public int largestPowerOf2(int target)
gets the largest power of 2 less than the targetNo Javadoc required
For the draft, implement sumEveryThird
to find the sum when the limit is 36. Do not use a loop for this. Just add the values in the code
(return 3 + 6 + ...). Do not just return 153.
But think about how you determine which numbers to include and when to stop. You will remove this code in the final and use a loop instead. Do not just print the literal answer
6C
Write a class Text
which has a constructor that takes a String of text. Implement the following methods.
public String getText()
returns the text public int getACount()
gets the number of a's in the String, either upper or lower case. Do not change the instance variablepublic String getDigitsOnly()
gets a String consisting of the digits in the text. You are provided with a helper method, isDigit()
which takes a String consisting of one character and returns true or false. You do not need to understand how it works. You can just use it.public String firsts()
returns a String consisting of the first characters of every word in the string. If the String is less than 2 characters long, return the string.indexOf (" ", fromIndex)
to control the loop and to determine where a new word starts. This version of indexOf returns the index of the first space after the fromIndex. indexOf
returns -1 if the space is not in the search stringProvide Javadoc
For the draft, provide the instance variable, constructor, getText() and getACount() methods along with the necessary Javadoc