Another method that might be desired is one that updates the Student’s number of credit hours. This method will receive a number of credit hours and add these to the Student’s current hours. Which of the following methods would accomplish this?


Another method that might be desired is one that updates the Student’s number of credit hours. This method will receive a number of credit hours and add these to the Student’s current hours. Which of the following methods would accomplish this?


a) public int updateHours( )

{

return hours;

}

b) public void updateHours( )

{

hours++;

}

c) public updateHours(int moreHours)

{

hours += moreHours;

}

d) public void updateHours(int moreHours)

{

hours += moreHours;

}

e) public int updateHours(int moreHours)

{

return hours + moreHours;

}

Answer: d. Explanation: This method will receive the number of new hours and add this to the current hours. The method in d is the only one to do this appropriately. Answer c is syntactically invalid since it does not list a return type. The answer in e returns the new hours, but does not reset hours appropriately. The Coin class, as defined in Chapter 4, consists of a constructor, and methods flip, isHeads and toString. The method isHeads returns true if the last flip was a Heads, and false if the last flip was a Tails. The toString method returns a String equal to “Heads” or “Tails” depending on the result of the last flip. Using this information, answer questions 16– 17