Results 1 to 20 of 30
Thread: Hello
- 01-18-2010, 08:25 PM #1
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
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
- 01-18-2010, 08:51 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
How do you know it's wrong? Compiler error? runtime error? We need a little more information in order to help you.
- 01-18-2010, 08:54 PM #3
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
have worked it out, the ">" should of been a "<"
this java is tricky, one typo and you spend ages pulling your hair out.
- 01-18-2010, 08:59 PM #4
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
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.
- 01-18-2010, 09:06 PM #5
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
is racingFrog1 a double?
- 01-19-2010, 10:54 AM #6
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
for some reason it does not recognise it, when I put in this
void RacingFrog getRacingFrog1()
But it doesn't look right. Any ideas
- 01-19-2010, 11:21 AM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
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.
- 01-19-2010, 11:29 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
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.
- 01-19-2010, 11:42 AM #9
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
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.
- 01-19-2010, 11:50 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
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?
- 01-19-2010, 12:00 PM #11
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
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.
- 01-19-2010, 12:20 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
In the same way that a picture saves a thousand words, an actual java class saves misunderstanding.
Anyway, what is your actual problem now?
- 01-19-2010, 10:31 PM #13
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)
- 01-21-2010, 04:16 PM #14
Member
- Join Date
- Dec 2009
- Posts
- 24
- Rep Power
- 0
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);
- 01-21-2010, 07:51 PM #15
Member
- Join Date
- Jan 2010
- Posts
- 46
- Rep Power
- 0
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
}
- 01-21-2010, 08:08 PM #16
Member
- Join Date
- Jan 2010
- Location
- England
- Posts
- 15
- Rep Power
- 0
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.
- 01-21-2010, 10:08 PM #17
Member
- Join Date
- Dec 2009
- Posts
- 24
- Rep Power
- 0
Hi Aggy
Which algorithm are you referring to?
- 01-21-2010, 10:23 PM #18
Member
- Join Date
- Dec 2009
- Posts
- 33
- Rep Power
- 0
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!
- 01-22-2010, 12:09 AM #19
Member
- Join Date
- Dec 2009
- Posts
- 24
- Rep Power
- 0
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?
- 01-22-2010, 07:58 PM #20
Member
- Join Date
- Dec 2009
- Posts
- 33
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks