6A
The Java Ski Resort has two types of rooms: Mountain View and Street Side. The rooms can accommodate either two or 4 people. The rates are higher in winter than in the summer. Room charges are in the given table.
Mountain | Street | |||
---|---|---|---|---|
2 people | 4 people | 2 people | 4 people | |
Winter | $250.00 | $370.00 | $200.00 | $325.00 |
Summer | $175.00 | $260.00 | $150.00 | $200.00 |
Complete the class Room. It has a constructor that takes three parameters:
public Room(String view, String season, int occupants)
It also has a methods:
public double getCost()
- gets the cost of the specified roompublic void setOccupants(int occupants)
- sets the number of occupants renting this Roompublic String getSeason()
- gets the season during which this room is rented.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. If view is a String other than "Mountain" or "Street", charge the rate for "Mountain". If the season is anything other than "Summer" or "Winter", charge the rate for "Winter." Use nested if statements.
You may use the litterals 1, 2, 3, and 4, but define and use constants for the room charges.
For the draft, write the javadoc for the constructor and the methods. Implement the constructor and getSeason method. Provide stub for the getCost and setOccupants methods so that your class will compile with the tester.
6B
Complete the MyNumber class. The class has a constructor that takes a positive int parameter and has the following methods.
public int getOddSum()
gets the sum of all the odd positive numbers less than or equal to this MyNumber. You may be able to do this with a matematical formula, but don't. You need to use a looppublic int laregestPowerOfTwo()
gets the largest power of 2 that is less than the number. For example if the number is 10, the method will return 8 (23). If the number is less than 1, return -1 to indicate that there is no power of 2 less than the number. Use a looppublic void setNumber(int value)
- provided for youFor the draft: For the draft, implement getOddSum
as a stub. For largestPowerOfTwo
, return -1 if the number is less than 2, return -1. otherwise return 0 for now. Also provide Javadoc for the two methods.
6C
Complete the TextUtil class. The class has a constructor that takes a String parameter and the following methods.
public int getCount()
returns the number of characters in this textpublic int upperCaseCount()
gets the number of uppercase letters in the text. You can use the String contains methodpublic String getEverySecondLetter()
gets a string that contains every other character, starting with the character at index 0For the draft, implement the getCount. Implement the other two methods as stubs. Write Javadoc for all three methods.