This site requires JavaScript, please enable it in your browser!
Greenfoot back
avocasso
avocasso wrote ...

2013/2/19

Create a shuffling method, Please help! Thanks

avocasso avocasso

2013/2/19

#
Create a shuffle method using the below pseudo code as a guide: create a new empty arraylist (called newList) while <there are still songs left> randomly select the index of one song on the playlist remove it from the current playlist and place it at the end of newList songs = newList Hint: Generate a random number using the Random class in the Java library. Its method is: public int nextInt(int n). This returns a pseudorandom, uniformly distributed int value as low as 0 and as high as n. Therefore, nextInt(songs.size()) gives you a random index. Remember that the size of songs lessens by one each time you add a randomly selected song to newList. You will need to account for this each time you generate a random number.
danpost danpost

2013/2/19

#
What you need to do is pretty well spelled out in the description. Just look over the class APIs for java.util.Random, java.util.ArrayList and the interface java.util.List to determine what other methods (not specified above) you might need. Also, note what constructors are available for the classes. Java APIs
You need to login to post a reply.