...

View Full Version : Java string error.



Vain12
05-25-2008, 09:29 PM
I need to write a public instance method called performDance() which takes no
arguments and returns no value.

The method should check to see if numOfDanceMoves is greater than 0, if it is the method should get the dancing frogs to do danceMove1, and so on.

I'm receiving an error 'setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String)'

This is the code for the whole class.



public class FrogDanceCoordinator
{
/**
* Default constructor for objects of class FrogDance
*/
public FrogDanceCoordinator()
{
super();
}

public void isValidNumOfMoves()
{
String NumMoveString;
int NumMove;
NumMoveString = OUDialog.request("Please enter a number");
NumMove = Integer.parseInt(NumMoveString);
if (NumMove < 1 || NumMove > 5)
{
OUDialog.alert("true");
}
else
{
OUDialog.alert("false");
}
}

public void isValidMove()
{
String move;
move = OUDialog.request("Please enter a move");
if (move.equals("flip") || move.equals("side"))
{
OUDialog.alert("true");
}
else
{
OUDialog.alert("false");
}
}

public void promptForNumOfMoves()
{
String stringInput;
int intInput;
stringInput = OUDialog.request("Please enter a number");
intInput = Integer.parseInt(stringInput);
if ((intInput <= 5) && (intInput >= 1))
{
OUDialog.alert("Your number of moves are" + intInput);
}
else
{
stringInput = OUDialog.request("Please enter a valid number");
}
}

public String promptForDanceMove()
{
String DanceMove;
DanceMove = OUDialog.request("Please enter a move");
while (DanceMove.equals("flip") || DanceMove.equals("side"))
{
DanceMove = OUDialog.request("Please enter a valid dance move, flip or side");
}
return DanceMove;
}

private int numOfFrogsDancing;
private int numOfDanceMoves;

private Frog frog1;
private Frog frog2;
private Frog frog3;

public FrogDanceCoordinator (Frog frog1, Frog frog2, Frog frog3)
{

this.frog1=frog1;
this.frog2=frog2;
this.frog3=frog3;

}



public void selectDancingFrogs()
{
Frog[] frog = {frog1,frog2,frog3};
numOfFrogsDancing = 0;
for (int i=0; i<frog.length; i++)
{
boolean result;
result = OUDialog.confirm("Please confirm if you want Frog"+ i + " to dance");
if (result)
{
numOfFrogsDancing++;
frog[i].setColour(OUColour.YELLOW);
}
else
{
numOfFrogsDancing++;
frog[i].setColour(OUColour.GREEN);
}
}
}



public void flip(Frog frog)
{
frog.jump();
if (frog.getPosition()==1)
{
frog.setPosition(11);
}
else
{
if (frog.getPosition()==11)
{
frog.setPosition(1);
frog.jump();
}
}
}

public void side(Frog frog)
{
if (frog.getPosition()==1)
{
frog.setPosition(11);
}
else
{
if (frog.getPosition()==11)
{
frog.setPosition(1);
frog.jump();
}
}
}

public void flipDancingFrogs(Frog frog)
{
this.selectDancingFrogs();
this.flip(frog);
}

public void slideDancingFrogs(Frog frog)
{
this.selectDancingFrogs();
this.side(frog);
}

private String danceMove1;
private String danceMove2;
private String danceMove3;
private String danceMove4;
private String danceMove5;

public FrogDanceCoordinator (String danceMove1, String danceMove2, String danceMove3, String danceMove4, String danceMove5)
{

this.danceMove1=danceMove1;
this.danceMove2=danceMove2;
this.danceMove3=danceMove3;
this.danceMove4=danceMove4;
this.danceMove5=danceMove5;

}


public int createDance()
{
String StringDanceMoves;
StringDanceMoves = OUDialog.request("Please enter the number of dance moves");
numOfDanceMoves = Integer.parseInt(StringDanceMoves);
danceMove1 = OUDialog.request("Please enter a move, flip or side");
if (numOfDanceMoves > 1)
{
danceMove2 = OUDialog.request("Please enter another dance move");
}

if (numOfDanceMoves > 2)
{
danceMove3 = OUDialog.request("Please enter another dance move");
}

if (numOfDanceMoves > 3)
{
danceMove4 = OUDialog.request("Please enter another dance move");
}

if (numOfDanceMoves > 4)
{
danceMove5 = OUDialog.request("Please enter another dance move");
}
return numOfDanceMoves;
}

public void setUpDance()
{
this.selectDancingFrogs();
this.createDance();
}

public void performDance()
{
if (numOfDanceMoves > 0)
{
this.setUpDance(danceMove1);
}

if (numOfDanceMoves > 1)
{
this.setUpDance(danceMove2);
}

if (numOfDanceMoves > 2)
{
this.setUpDance(danceMove3);
}

if (numOfDanceMoves > 3)
{
this.setUpDance(danceMove4);
}

if (numOfDanceMoves > 4)
{
this.setUpDance(danceMove5);
}
}
}

Gox
05-26-2008, 09:21 AM
Your method setUpDance is declared as taking no parameters "public void setUpDance()", however when you call this method you're passing it a string as a parameter "this.setUpDance(danceMove1)".

This is a compilation error of course as the call to a method must match the signature of the method. So, either you forgot to declare the method as taking a parameter (public void setUpDance(String danceMove)) or you're accidentally passing the method a parameter when you didn't mean to.

Vain12
05-26-2008, 12:52 PM
I've changed that, but I'm still getting the same error unfortunately.

Gox
05-27-2008, 08:40 AM
You made sure to change it for
this.setUpDance(danceMove2)
this.setUpDance(danceMove3)
this.setUpDance(danceMove4)
this.setUpDance(danceMove5)
as well?

The java compiler should tell you the line number associated with each compilation error. Can you provide which line of code the compiler is complaining about?

i.e. setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String)' : line 5

Vain12
05-27-2008, 01:48 PM
Nope, it just gave it as an error. I'm using a software called BlueJ.

Gox
05-27-2008, 08:52 PM
When I try to compile your code I get lots of errors, because I don't have all of your project code. However, more of importance is that I get the following 5 compilation errors regarding setUpDance()


setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String) : line 210
setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String) : line 215
setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String) : line 220
setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String) : line 225
setUpDance() in FrogDanceCoordinator cannot be applied to (java.lang.String) : line 230

These errors correspond to the following lines of code (which we've talked about already).

this.setUpDance(danceMove1)
this.setUpDance(danceMove2)
this.setUpDance(danceMove3)
this.setUpDance(danceMove4)
this.setUpDance(danceMove5)
The compiler doesn't give me any additional errors for setUpDance(). My suggestion is to first double-check your code to make sure you've changed the 5 setUpDance() calls to whatever your "fix" was for this error. If all of the calls seem fine then repost your full code again and we'll have a closer look.

Gox



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum