Using Objects and Methods unit test
A test on this unit alone, marked as a percentage and a letter grade — for the test your class is actually sitting, rather than for May. Answer everything, then submit once: seeing the answer to question 3 before attempting question 4 makes the final percentage meaningless.
Return type
String concatenation
boolean
Class vs object
Math.random
nextInt then nextLine
null
Instantiation
Method overloading
int
Compound assignment
length()
Short answer 1. Define or explain: System.out.print vs println
3 ptsShort answer 2. Define or explain: Random integer in a range
3 ptsShort answer 3. Define or explain: Passing a primitive to a method
3 ptsShort answer 4. Define or explain: compareTo
3 ptsFree response
9 ptsMETHODS AND CONTROL STRUCTURES (Question 1, 9 points). A dog-walking company is represented by the DogWalkCompany class, which provides two helper methods: int numAvailableDogs(int hour) returns the number of dogs (always > 0) available for a walk at the given hour (0–23), and void updateDogs(int hour, int numberDogsWalked) decreases the number of available dogs at that hour by numberDogsWalked (> 0). A dog walker is represented by the DogWalker class, with private instance variables int maxDogs (the most dogs the walker can handle in an hour, > 0) and DogWalkCompany company. You will write two DogWalker methods: public int walkDogs(int hour) — the walker walks as many dogs as the company has available at that hour, capped at maxDogs; the method must use updateDogs to claim those dogs and returns the number walked. (E.g., 10 available with maxDogs 4 → walk 4; 3 available with maxDogs 4 → walk 3.) public int dogWalkShift(int startHour, int endHour) — performs one-hour walks for every hour from startHour to endHour inclusive and returns total pay. Each hour pays $5 per dog walked, plus a $3 bonus for that hour if the walker walked maxDogs dogs OR the hour is in the peak range 9–17 inclusive. (Example: with maxDogs 3 and availability such that the walker walks 3, 2, 2, 3 dogs at hours 7–10, pay is 18 + 10 + 13 + 18 = $59.) Assume walkDogs works as specified; you must use it appropriately.
A. Complete method walkDogs. You must use numAvailableDogs and updateDogs appropriately to receive full credit.
B. Complete method dogWalkShift. Assume walkDogs works as specified regardless of part (a); you must use walkDogs appropriately to earn full credit.