• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to implement Decrementing Carousel With Limit

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this implementation I must produce a carousel run, which limits number of calls to the next method. When the limit of calls reached carousel run must consider itself finished.

Carousel Run class:


Decrementing Carousel class:


DecrementingCarouselWithLimitedRun class


DecrementingCarouselWithLimitRun class:

This is Main class:


When I'm running the code I get:

But it should be:


How I stop the code to run only for a limited times?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a variable which keeps track of the "number of times". When you're about to start on another "time" then add 1 to it. Or if that would cause it to exceed the "number of times" then don't start on that next "time".

Since you're creating one of your Carousel object for each "time" (or so I think) it would be easiest to use a static variable.

Or if you're talking about restricting the number of times that run() is called starting at line 13, maybe you could just remove some of those lines to satisfy the number-of-times rule.
 
Cris Marinescu
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly, I need to restrict the number of times that run() is called. You suggested me to remove some lines but I'm not sure which ones.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 25 in the Main class for example.
 
Cris Marinescu
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did that and I get this result, which is wrong:



I only needed to run the next() from a limited times, in my example from above is 10
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you could fix it, please let me know
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RM: welcomw to the Ranch

You might not have noticed our code button, but I used it on your code and doesn't it look better now
 
reply
    Bookmark Topic Watch Topic
  • New Topic