A city parking meter charges by the hour. The price of an hour depends on the time of day, and no single stay costs more than a daily maximum. The meter also prints receipts that hide most of a car's license plate. You will write two methods of the ParkingMeter class.public class ParkingMeter
{
/** Returns the price, in cents, of parking during the
* hour that starts at hour (0 to 23).
*/
public int rateFor(int hour)
{ /* implementation not shown */ }
/** Returns the most a driver pays for a stay, in cents.
*/
public int getDailyMax()
{ /* implementation not shown */ }
/** Returns the cost, in cents, of parking for the given
* number of whole hours starting at startHour, as
* described in part (a).
* Precondition: 0 <= startHour <= 23, 1 <= hours <= 24
*/
public int costOfStay(int startHour, int hours)
{ /* to be implemented in part (a) */ }
/** Returns plate with every character except the last
* two replaced by "*", as described in part (b).
* Precondition: plate.length() >= 2
*/
public static String maskPlate(String plate)
{ /* to be implemented in part (b) */ }
/* There may be instance variables, constructors,
* and methods that are not shown. */
}Examples for part (a): the meter in these examples has the rates below and a daily maximum of 1500 cents.
| Hours | Value of rateFor(hour) |
|---|---|
| 0 to 7 | 50 |
| 8 to 17 | 300 |
| 18 to 21 | 150 |
| 22 and 23 | 50 |
| Call | Hours charged | Return value |
|---|---|---|
costOfStay(16, 3) | 16, 17, 18 | 750 |
costOfStay(22, 4) | 22, 23, 0, 1 | 200 |
costOfStay(7, 8) | 7 to 14 | 1500 (the total, 2150, is above the maximum) |
Examples for part (b):
| Call | Return value |
|---|---|
maskPlate("KX4729") | "****29" |
maskPlate("7TRC118") | "*****18" |
maskPlate("AB") | "AB" |