Results 1 to 5 of 5
  1. #1
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default 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. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    indentation would really help you.

    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. #3
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    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. #4
    senorbum is offline Member
    Join Date
    Aug 2009
    Posts
    76
    Rep Power
    0

    Default

    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. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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.

Similar Threads

  1. Problem with click to move ball algorithm
    By Laythe in forum Java Applets
    Replies: 1
    Last Post: 12-19-2009, 01:00 AM
  2. O(log n) algorithm help !!!!!!
    By itseeker87 in forum New To Java
    Replies: 8
    Last Post: 09-09-2008, 06:12 PM
  3. Problem with equation in my algorithm
    By romina in forum New To Java
    Replies: 2
    Last Post: 07-20-2007, 08:53 AM
  4. Problem with algorithm
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-13-2007, 04:31 PM
  5. Algorithm problem
    By Marcus in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 02:37 AM

Posting Permissions

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