Results 1 to 6 of 6
- 04-14-2010, 01:20 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Semantic Error: Message not understood by class
Hi everyone, I am new to these forums, however have done a search, and looked at the results on others with this problem, however none seem to solve it, so here goes.
I am trying to write a method that asks the user for a number of cycles to repeat for, and also a size for each cycle. The size is used in the call for another method. Ill put the method that I have a problem with here, and if the entire code below.
Java Code:public void runLight(int numCycles,int sizePerCycle) { for (int doneCycles = 0; doneCycles <= numCycles; doneCycles++) { this.lightCycle(sizePerCycle); } }
Java Code:Semantic error: Message runLight() not understood by class'DiscoLight'
Java Code:import ou.*; /** * The class Circle defines a shape with the characteristics of a circle. * * @author M255 Course Team * @version 1.0 */ public class Circle extends OUAnimatedObject { /* Instance variables */ private int diameter; private OUColour colour; private int xPos; private int yPos; /** * Constructor for objects of class Circle with the default characteristics. */ public Circle() { this.diameter = 20; this.colour = OUColour.BLUE; this.xPos = 30; this.yPos = 30; } /* Instance methods */ /** * Sets the diameter of the receiver to the value of the argument aDiameter */ public void setDiameter(int aDiameter) { this.diameter = aDiameter; this.update(); } /** * Returns the diameter of the receiver. */ public int getDiameter() { return this.diameter; } /** * Sets the colour of the receiver to the value of the argument aColour. */ public void setColour (OUColour aColour) { this.colour = aColour; this.update(); } /** * Returns the colour of the receiver. */ public OUColour getColour () { return this.colour; } /** * Sets the horizontal position of the receiver to the value of the argument x. */ public void setXPos(int x) { this.xPos = x; this.update(); } /** * Returns the horizontal position of the receiver. */ public int getXPos() { return this.xPos; } /** * Sets the vertical position of the receiver to the value of the argument y. */ public void setYPos(int y) { this.yPos = y; this.update(); } /** * Returns the vertical position of the receiver. */ public int getYPos() { return this.yPos; } /** * Returns a string representation of the receiver. */ public String toString() { return "An instance of class "+ this.getClass().getName() + ": position (" + this.getXPos() + ", " + this.getYPos() + "), diameter " + this.getDiameter() + ", colour " + this.getColour(); } }
Java Code: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); } public void setLight(Circle aCircle) { this.light = aCircle; } 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.setColour(OUColour.GREEN); this.light.setXPos(122); this.light.setYPos(162); this.setLight(aCircle); } /** * Randomly sets the colour of the instance variable * light to red, green, or purple. */ public void changeColour() { int randomInt = getRandomInt(3); if (randomInt == 0) { this.light.setColour(OUColour.RED); } else if (randomInt == 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) { int curDiameter = this.light.getDiameter(); while(curDiameter < size) { this.light.setDiameter(curDiameter + 2); this.light.setXPos(this.light.getXPos() - 1); this.light.setYPos(this.light.getYPos() - 1); this.changeColour(); curDiameter += 2; this.delay(100); } } /** * 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) { int curDiameter = this.light.getDiameter(); while(curDiameter > size) { this.light.setDiameter(curDiameter - 2); this.light.setXPos(this.light.getXPos() + 1); this.light.setYPos(this.light.getYPos() + 1); this.changeColour(); curDiameter -=2; this.delay(100); } } /** * 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) { int oldDiameter = this.light.getDiameter(); this.grow(sizeIncrease); this.shrink(oldDiameter); } /** * 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(int numCycles,int sizePerCycle) { for (int doneCycles = 0; doneCycles <= numCycles; doneCycles++) { this.lightCycle(sizePerCycle); } } /** * 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); } } }
Many Thanks
James
- 04-14-2010, 01:56 PM #2
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Upon doing some more investigation, I have found that if I use the following code, it executes just fine, but it offers no flexibility and doesn't answer the question (to allow user to choose number of cycles and size of cycle)
Java Code:public void runLight() { int sizeCycle = 100; this.lightCycle(sizeCycle); this.lightCycle(sizeCycle); this.lightCycle(sizeCycle); this.lightCycle(sizeCycle); }
On the other hand, if I slightly modify the code, like below, I get the same error as my first post.
Java Code:public void runLight(int sizeCycle) { //int sizeCycle = 100; this.lightCycle(sizeCycle); this.lightCycle(sizeCycle); this.lightCycle(sizeCycle); this.lightCycle(sizeCycle); }
- 04-14-2010, 08:15 PM #3
Senior Member
- Join Date
- Feb 2009
- Posts
- 312
- Rep Power
- 13
Where is the runLight() method being called?
- 04-14-2010, 11:14 PM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 952
- Rep Power
- 12
Like StormyWaters, I cannot see where your runLight() method is being called, but from what you're describing, it seems like it's being called without parameters, and so the compiler complains when the only version it can find is one with parameters.
-Gary-
- 04-15-2010, 12:10 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
I'm calling it in a Workspace, but yes, without parameters.
I tested calling it with parameters, eg runLight(5,120) and it worked fine. Only problem is that the solution called for me to test it by using just runLight(), it should prompt the user for the parameters, how might I go about doing that?
- 04-15-2010, 03:39 PM #6
Senior Member
- Join Date
- Feb 2009
- Posts
- 312
- Rep Power
- 13
That all depends on how you want to prompt the user. Are you using a GUI or are you doing it all on the command line?
If using a GUI, I would suggest taking a look at the JOptionPane class (http://java.sun.com/j2se/1.4.2/docs/...ptionPane.html) as it already has some handy predefined methods for doing this.
If going by the command line, take a look at the Scanner class(http://java.sun.com/j2se/1.5.0/docs/...l/Scanner.html).
Similar Threads
-
Help with servlet error message
By ricky_40 in forum New To JavaReplies: 1Last Post: 03-08-2010, 07:01 AM -
Semantic error: Message incrementMedalCount() not understood by class'OlympicFrog'
By darkblue24 in forum New To JavaReplies: 1Last Post: 02-15-2010, 11:32 PM -
Error Message????
By Cubba27 in forum New To JavaReplies: 11Last Post: 11-21-2009, 03:46 PM -
TreeMap class and message not understood issues - help please
By trueblue in forum New To JavaReplies: 8Last Post: 07-22-2009, 02:16 AM -
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 03:10 AM
Bookmarks