dimanche 26 janvier 2020

I want to write a public instance method called runExperiments() which takes no argument and returns no value

The method should attempt to decrement powerLevel by a random number between 1 and 3 inclusive for each experiment up to numberOfExperiments. You should make use of the supplied helper method randomInteger() for this.

Can someone please help me with my code. below is where I am stuck. I am not sure how to get random number by using the info abpve. Here is the complete code. Many thanks

 public void runExperiments()

and here is the full code:

public class SpaceRocket extends FlyingObject implements Launchable
{
 private int maxPowerLevel;    
 private int numberOfExperiments;
 private int powerLevel;

 public int getMaxPowerLevel()
{
 return this.maxPowerLevel;
}

 public int getNumberOfExperiments()
{
  return this.numberOfExperiments;
}
  public int getPowerLevel()
{
  return this.powerLevel;
 }
 public SpaceRocket(String aName, int aNumberOfExperiments)
{
 this.name = aName;  
 this.numberOfExperiments = aNumberOfExperiments;
 this.powerLevel = 0;
 this.maxPowerLevel = 15;
 }

public boolean decrementPower(int powerReduction)
  {
if (powerReduction > this.getPowerLevel()){
 this.powerLevel = 0;  
 return false;
 } 
 else
 {
 this.powerLevel = powerReduction;
return true;
   }
  }

This is what I have done so far:

    public void runExperiments()
    {
     this.powerLevel -= randomInteger(1,3);

     }



Aucun commentaire:

Enregistrer un commentaire