Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: Hello

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

    Default Hello

    hello all, am new here and am sorry my first post is a request for knowledge.

    I am studying with the OU and am studying java and have hit a bit of a stumbling block. Can someone give me a hint as to why this snippit of code is wrong.?

    public void moveToPosition(int move)
    {
    while(this.getPosition() != move)
    {
    this.jump();
    if(this.getPosition() > move)
    {
    this.right();
    }
    else
    {
    this.left();
    }
    }
    }

    i don't the answer just an idea of what i have messed up.

    thanks
    Aggy

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    How do you know it's wrong? Compiler error? runtime error? We need a little more information in order to help you.

  3. #3
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    have worked it out, the ">" should of been a "<"

    this java is tricky, one typo and you spend ages pulling your hair out.

  4. #4
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    here's a new problem.

    /**
    * Returns the value of racingFrog instance variable.
    */
    private Double getRacingFrog1()
    {
    return this.racingFrog1;
    }

    /**
    * Sets the value of the racingFrog instance variable to the value of
    * the argument.
    */
    private void setFrog1(RacingFrog aRacingFrog1)
    {
    this.racingFrog1 = racingFrog1;
    }

    comes back stating that i have inputted incompatible types.

    this is very frustrating.

  5. #5
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    is racingFrog1 a double?

  6. #6
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    for some reason it does not recognise it, when I put in this

    void RacingFrog getRacingFrog1()

    But it doesn't look right. Any ideas

  7. #7
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    6

    Default

    Quote Originally Posted by Aggy View Post
    for some reason it does not recognise it
    If you get an error message, it would help if you post up the exact error message text - Java error messages generally tell you what is wrong and where.

    In this case, you need the method parameter for setFrog1, and the return type from getRacingFrog1, and the racingFrog1 member variable, all to be the same type, either RacingFrog or Double, whichever is correct. If you get an error message, post it here.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    You'll need to show us what racingFrog1 is.
    According to your getRacingFrog1 it's a Double class, and according to your setFrog1 it's a RacingFrog1 class.

  9. #9
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    racingfrog is a subclass of the frog class if that makes sense, and when i compile it with the

    public RacingFrog racingFrog1()

    it does not come up with any errors.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Which is as expected, if racingFrog1 is a RacingFrog.
    Can you give us some more of the class containing racingFrog1 and we might be able to explain what's happening?

  11. #11
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    the class for racingfrog contains an instance method for moving to a position and calls all other stuff (Super()) from the frog class which holds position, colour, height, etc.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    In the same way that a picture saves a thousand words, an actual java class saves misunderstanding.

    Anyway, what is your actual problem now?

  13. #13
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    In impending threads, please use a title that is relevant to your question.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  14. #14
    owlsno1 is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    Hi

    Think i am doing the same question but have created a slighlty different code but still having problems executing the code.This is the code i have:

    public RacingFrog()
    {
    super();
    selected = false;
    )


    /* instance methods */

    /**
    * Sets the value of the selected instance variable to the value
    * of the argument.
    */
    public void setSelected(boolean aValue)
    {
    this.selected = aValue;

    Public void moveToPosition()
    set moveToPosition (int num)
    if (RacingFrog.moveToPosition()==1)
    RacingFrog.moveToPosition(11);

    else

    if (RacingFrog.moveToPosition()==11)
    RacingFrog.moveToPosition(1);
    RacingFrog.jump();
    }

    }
    It comes up with the following error

    Semantic error: Message moveToPosition( int ) not understood by class'RacingFrog'

    when testing the method
    RacingFrog rf = new RacingFrog()
    rf.moveToPosition(5);

  15. #15
    Newbie666 is offline Member
    Join Date
    Jan 2010
    Posts
    46
    Rep Power
    0

    Default

    Public void moveToPosition()
    needs an int as a parameter, and you probably want some curly braces around that function.

    Public void moveToPosition(int position)
    {

    // stuff goes here

    }

  16. #16
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    anyone moved onto the algorithm yet, have written it best i can but am having more problems and the tutor ain't replying to diddly squat.

  17. #17
    owlsno1 is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    Hi Aggy

    Which algorithm are you referring to?

  18. #18
    evant is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Default

    Im currently stuck on the select runners bit...the rest of the code compiles from the previous questions, not entirely sure if its correct or not but i presume so.
    Hope i do better on this TMA as the previous one my tutor messaged saying perhaps i shouldnt be doing programming..HAHA!

  19. #19
    owlsno1 is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    Hey up Evant

    Seems me you and you are the same predicament, don't think i want to be doing programming either. I've done the first part of question 1 but cant stop my frog jumping on every step instead of just jumping when it arrives at its designated step.Any advice?

  20. #20
    evant is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Default

    Hi, yea thats what mine does, firstly i thought it was suppose to jump but after reading it again i guess not..will have a look now and see if i can figure out why.

Page 1 of 2 12 LastLast

Posting Permissions

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