I am having problem with the following code

public void grow(int size), can't seem to get it working

import ou.*;
import java.util.*;
/**
 * Class DiscoLight
 * This class uses the Circle class, and the Shapes window 
 * to simulate a disco light, that grows and shrinks and 
 * changes colour. 
 * 
 * @author M255 CT
 * @version 1.0
 */

public class DiscoLight
{
   /* instance variables */
   private Circle light;   // simulates a circular disco light in the Shapes window
   private Random randomNumberGenerator;

   /**
    * Default constructor for objects of class DiscoLight
    */
   public DiscoLight()
   {
      super();
      this.randomNumberGenerator = new Random();           
   }


   /**
    * Returns a randomly generated int between 0 (inclusive) 
    * and number (exclusive). For example if number is 6,
    * the method will return one of 0, 1, 2, 3, 4, or 5.
    */
   public int getRandomInt(int number)
   {
      return this.randomNumberGenerator.nextInt(number);
   }


   /** 
    * student to write code and comment here for setLight(Circle) for Q4(i)
    */
   public void setLight(Circle aCircle)
   {
       this.light = aCircle;

   }


   /**
    * student to write code and comment here for getLight() for Q4(i)
    */
   public Circle getLight()
   {
       return this.light;
   }

   /** 
    * Sets the argument to have a diameter of 50, an xPos 
    * of 122, a yPos of 162 and the colour GREEN.
    * The method then sets the receiver's instance variable
    * light, to the argument aCircle.
    */ 
   public void addLight(Circle aCircle)
   {
      //Student to write code here, Q4(ii)
      this.light = aCircle;
      this.light.setDiameter(50);
      this.light.setXPos(122);
      this.light.setYPos(162);
      this.light.setColour(OUColour.GREEN);
   }


   /** 
    * Randomly sets the colour of the instance variable 
    * light to red, green, or purple.
    */  
   public void changeColour() 
   { 
       int i = getRandomInt(3); 
       if (i == 0) 
       { 
           this.light.setColour(OUColour.RED); 
       } 
       else if (i == 1) 
       { 
           this.light.setColour(OUColour.GREEN); 
       } 
       else 
       { 
            this.light.setColour(OUColour.PURPLE); 
       } 
   } 



   /** 
    * Grows the diameter of the circle referenced by the 
    * receiver's instance variable light, to the argument size.  
    * The diameter is incremented in steps of 2,
    * the xPos and yPos are decremented in steps of 1 until the
    * diameter reaches the value given by size. 
    * Between each step there is a random colour change.  The message 
    * delay(anInt) is used to slow down the graphical interface, as required.
    */   
   public void grow(int size)
   {    
       for (int i = 0; i < size; i++)
       {
           this.aDiameter[i] = aDiameter + 2;
           this.xPos[i] = xPos - 1;
           this.yPos[i] = yPos - 1;
       }
   }


   /** 
    * Shrinks the diameter of the circle referenced by the 
    * receiver's instance variable light, to the argument size.  
    * The diameter is decremented in steps of 2,
    * the xPos and yPos are incremented in steps of 1 until the
    * diameter reaches the value given by size. 
    * Between each step there is a random colour change.  The message 
    * delay(anInt) is used to slow down the graphical interface, as required.
    */     
   public void shrink(int size)
   {   
       //student to write code here, Q4(v)
   }


   /** 
    * Expands the diameter of the light by the amount given by
    * sizeIncrease (changing colour as it grows).
    * 
    * The method then contracts the light until it reaches its
    * original size (changing colour as it shrinks).
    */     
   public void lightCycle(int sizeIncrease)
   {
      //student to write code here, Q4(vi)
   }


   /** 
    * Prompts the user for number of growing and shrinking
    * cycles. Then prompts the user for the number of units
    * by which to increase the diameter of light.
    * Method then performs the requested growing and 
    * shrinking cycles.
    */     
   public void runLight()
   {  
    //student to write code here, Q4(vii)
   }  


   /**
    * Causes execution to pause by time number of milliseconds
    */
   private void delay(int time)
   {
      try
      {
         Thread.sleep(time); 
      }
      catch (Exception e)
      {
         System.out.println(e);
      } 
   }

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

the error is here:
this.aDiameter = aDiameter + 2;
it is not permited to assign an array to an integer value.

the error is here:
this.aDiameter = aDiameter + 2;
it is not permited to assign an array to an integer value.

No man this will not be a problem... you are adding integer in ur array , which is perfectly correct. Original post doesnt contain full code and it is giving lot of compile errors. Please post/attach full code.

No man this will not be a problem... you are adding integer in ur array , which is perfectly correct. Original post doesnt contain full code and it is giving lot of compile errors. Please post/attach full code.

If aDiameter is an array of integer it will be wrong the take it as an Integer, but aDiameter is an Integer so trying to assign an Integer to an Array wich is an Object is wrong and it is a big mistack.
I dont now if the code is incomplet or not but I'm tolking about this point adding an Integer to an Array of integer if wrong and it does not compile. if the right part of assignement is wrong then all the statement is wrong. and one more time this will be a big problem.

If aDiameter is an array of integer it will be wrong the take it as an Integer, but aDiameter is an Integer so trying to assign an Integer to an Array wich is an Object is wrong and it is a big mistack.
I dont now if the code is incomplet or not but I'm tolking about this point adding an Integer to an Array of integer if wrong and it does not compile. if the right part of assignement is wrong then all the statement is wrong. and one more time this will be a big problem.

aah.. .sorry couldn't read that properly... year you are right...
correct version will be
this.aDiameter = this.aDiameter + 2;

wouldn't while be a more suitable loop?

What do you make of the final three questions - almost there on (vi), nowhere near on (vii) :(

Edited 6 Years Ago by drohnwerks: n/a

This article has been dead for over six months. Start a new discussion instead.