Challenge for Class Code
Challenge
This is the Class Missile:
public class Missile { private int speed; private int fuel; public Missile(int rocketFuel) { speed = 0; fuel = rocketFuel; } public void fireRocket() { fuel = fuel - 1; speed = speed +1; } public int getSpeed() { return speed; } }
The following method appears in the same project in the Class ControlMissile. One of the lines of code in it will cause a compiler error. Can you find it and type in the correct version of that line?
public void accelerateMissileToSpeed(Missile missile, int speed) { while(missile.speed < speed){ missile.fireRocket(); } }
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.