Hello,
i'm justarting out with OOP with Java and i'm looking for a bit of help with a bit of code as i can't quite work out why it wont work as i'm still learning.
Here's what im being asked to do
write a public method called requestPositionsAndMove() which takes no arguments and returns no value. The method should request a use to enter a number for the position of startFrog using a dialogue box with the appropriate text. It should then do the same for the position of stopFrog. In each case it should assume that the user enters an integer, but if it is outside the range 1 to 11 inclusive a message informing the user that the positions must be in the range 1 to 11 inclusive should be displayed in a dialogue box and te request to re enter a number repeated. This should continue for as long as the user enters a number that is out of range. You should assume that the user does not press the cancel button. The method should then position startFrog and stopFrog according to the numbers entered or use a dialogue box to indicate an error has occurred and that this error is because the start and stop positions are the same.
Here is what i have so far. The code works a bit but not as it should;
public void requestPositionsAndMove()
{
String input;
int startpos = Integer.parseInt(OUDialog.request("Enter a start number between 1 & 11"));
int stoppos = Integer.parseInt(OUDialog.request("Enter a stop number between 1 & 11"));
if (startpos >11)
{
OUDialog.alert("The start number entered is not between 1 & 11 ");
OUDialog.request("Enter a start Number between 1 & 11");
}
if (stoppos >11)
{
OUDialog.alert("The stop number entered is not between 1 & 11 ");
OUDialog.request("Enter a stop Number between 1 & 11");
}
if (startpos==stoppos)
{
OUDialog.alert("An error has occurred as your start and stop positions are the same");
}
if ((startpos >=1) && (startpos <=11))
{
startFrog.setPosition(startpos);
}
if ((stoppos >=1) && (stoppos <=11))
{
stopFrog.setPosition(stoppos);
}
}
any help would be appreciated as i'm keen to learn but it's a bit of a struggle!