• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Loop help please

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am brand new to Java and it is my first programming language, but I'm struggling to understand loops. As part of the assignment I am doing, I have been given some code that I have to edit/add too depending on what the question asks. The question that I am stuck on is:

"Write an exercise() method in the RestrictedHoverFrog class that implements the following behaviour:

– If the second argument to the receiver has the value true, attempt to move the receiver left, then right, then right again, then left again – with this sequence of moves repeating according to the number of times specified by the first argument.

– If the second argument to the receiver has the value false, attempt to move the receiver right, then left, then left again, then right again – with this sequence of moves repeating according to the number of times specified by the first argument."

So far I got the following code. I know it's wrong and that it doesn't repeat the sequence, but I don't know how I can get it to repeat the sequence depending on the number of times specified by the first argument.




Any help will be really appreciated please
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to use a for loop?



The first parameter is your "counter". See if you can figure out how to make it loop.

[edit] This might be clearer if I had said:
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to The Ranch!
 
James Leon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

J. Kevin Robbins wrote:Do you know how to use a for loop?



The first parameter is your "counter". See if you can figure out how to make it loop.

[edit] This might be clearer if I had said:



Thank you so much!! Managed to get it working now
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 8395
601
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Leon wrote:

Try to avoid such writing as:
Instead, write:

If you'd ever by mistake manage to write:
You'd get unexpected results by assigning something to true on line 2.
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic