Re: Rép. : [Bluej-discuss] exercises 5.49 to 5.53

Michael Kölling M.Kolling at kent.ac.uk
Tue Mar 7 13:51:28 GMT 2006


The counter method is good and should work.

If you also want to stop moving the balls when they reach the edge,  
you could just remove every ball from the ArrayList when it reaches  
the 550 point (you do not need to remove it from screen, if you want).

Then, when the ArrarList is empty, you know it's time to stop.

Michael


On 7 Mar 2006, at 13:43, Yves Hamel wrote:

> Hi Luis,
>
> How about adding a counter? Each time a ball hits 550 pixels, that  
> counter increases and then you compare it to the size of the  
> Arraylist. Actually, going through each element of the ArrayList is  
> a  O(n) problem size where n is the number of elements in the  
> ArrayList , while using a counter turns it into a O(1) problem size  
> where this is a constant size no matter how many elements you have  
> in your ArrayList. Big O notation is a way to describe the problem  
> size in a matter of time execution and memory space. So,
> O(n) > O(1) and a O(n) problem can be very consuming for a large  
> set of elements (but most of the time you can't avoid it!)
>
> Yves
>
>>>> Luis.Moreira at jet.uk 03/07/06 4:03 am >>>
> Hi Guys,
>
> I am trying to do the exercises 5.49 to 5.53 and I am finding a few
> problems, so I decided to check with you.
>
> I have done exercise 5.49 by using an ArrayList as it seemed the best
> solution here, I also done exercise 5.51 and both seem to work OK. The
> problem I am having is with the erase() and how to finish the program.
> At the moment when the first ball gets to 550 pixels the program
> execution will stop I would like to stop it when the last ball reaches
> 550 pixels.
>
> I can see that I can do something like Iterate through the  
> ArrayList and
> check if all the balls have reached 550 pixels and then finish, but  
> that
> seems to me as using to many resources...
>
> Any thoughts welcomed.
>
> Thanks for all the help.
>
> Best regards
>
>                         Luis
>
>
>
>
>
>
>
>
> _______________________________________________
> mailing list bluej-discuss at bluej.org
> To unsubscribe or change your preferences, go to
> http://lists.bluej.org/mailman/listinfo/bluej-discuss



More information about the bluej-discuss mailing list