Question: Extensions in the Swift Programming: The Big Nerd Ranch Guide (2nd Ed.) e-book: The emptyGas(by:) method has some bugs. For example, if the current gasLevel
"Extensions" in the Swift Programming: The Big Nerd Ranch Guide (2nd Ed.) e-book: The emptyGas(by:) method has some bugs. For example, if the current gasLevel is less than the amount to remove, then the new value for this property will be negative. A negative value does not make sense and will actually stop the program from running (recall the precondition() in gasLevels property observer). Revise emptyGas(by:)s implementation to ensure that gasLevel is not decremented to be a negative value.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
