1. Member
Join Date
Jan 2010
Location
England
Posts
15
Rep Power
0

## Algorithm Problem

Can someone look at this algorithm for me and tell me why it does not compile and if it actually makes sense.

/**
* Creates a loop to determine how many frogs will take part in the race.
*/
public int Members(); //1
public int selected();
public int frogNumber();

public int Members = 0;
{
while(this.Members < 2)
this.frogNumber1 = false;
this.frogNumber2 = false;
this.frogNumber3 = false;
{
for (int frogNumber = 1; frogNumber < 3; frogNumber = frogNumber + 1)
OUDialog.confirm("Is " + this.frogNumber() + " taking part in the race");
if (selected = true)
{
frogNumber() = true;
selected++;
}
else
{
frogNumber() = false;
}
if (selected < 2)
{
OUDiag.confirm("A race must have at least two runners to be able to start");
selected = 0;
}
}
}

I get the "missing method body, or declare adstract" on the line marked //1

2. Senior Member
Join Date
Oct 2009
Location
California,US
Posts
201
Rep Power
8

Java Code:
```/**
* Creates a loop to determine how many frogs will take part in the race.
*/
public int Members(); //1
public int selected();
public int frogNumber();

public int Members = 0;
{
while(this.Members < 2)
this.frogNumber1 = false;
this.frogNumber2 = false;
this.frogNumber3 = false;
{
for (int frogNumber = 1; frogNumber < 3; frogNumber = frogNumber + 1)
OUDialog.confirm("Is " + this.frogNumber() + " taking part in the race");
if (selected = true)
{
frogNumber() = true;
selected++;
}
else
{
frogNumber() = false;
}
if (selected < 2)
{
OUDiag.confirm("A race must have at least two runners to be able to start");
selected = 0;
}
}
}```
Ok whats your reason why the code is not compiling?

3. Member
Join Date
Jan 2010
Location
England
Posts
15
Rep Power
0
I do indent and the reason it is not compiling is because it says that the variable Members is not recognised or declared, so do i declare it like I have done or do I have to declare something else.?

4. Member
Join Date
Aug 2009
Posts
76
Rep Power
0
public int Members();
should be
public int members;

The same goes for the other variables.

That being said, there are lots of things wrong with the code. But that is a place for you to start.

5. You are also missing {}'s after your while loop, f (selected = true) should use == not = since a single = is assignment not comparison, you only use () after method names, not fields, and you really need to use [code] [/code] tags when posting code here so we can read it. In a nutshell, you need to re-read the tutorials on basic code structure, you're improperly using syntax all over the place.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•