Question: Java Programming language d. Write a public instance method decrementPower() that takes a single int argument representing the amount to decrease the power Level (down



Java Programming language
d. Write a public instance method decrementPower() that takes a single int argument representing the amount to decrease the power Level (down to a minimum of 0) and returns a boolean. If the supplied argument is greater than power Level then powerLevel should be set to 0, and false should be returned. . Otherwise power Level should be reduced by the supplied argument and true should be returned. Check that when you execute decrementPower() on a new instance of SpaceRocket that it returns false when passed a positive argument. i. Write a public instance method called runExperiments() which takes no argument and returns no value. The method should attempt to decrement power Level by a random number between 1 and 3 inclusive for each experiment up to numberOfExperiments. You should make use of the supplied helper method random Integer() for this. If the power Level can be reduced, a message indicating the experiment number (starting at 1) should be displayed. If not, a suitable message should be displayed and remaining experiments should not be attempted. When all experiments have finished it should display "Experiment run stopped". Write this method, choosing a suitable kind of loop to control the number of iterations required. Hints: 1. Don't forget to make use of the return value from decrementPower(). 2. Experiments should not yet run as the default value of power Level is 0. f. It is now required that instances of SpaceRocket, along with instances of Kite and Stuntkite, implement Launchable behaviour, each in its own way. The Launchable interface specifies three methods: launch(), which takes no argument and returns no value, isAbleToFly(), which takes no argument and returns true or false, and land() which takes no argument and returns no value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
