Guest User

Untitled

a guest
Oct 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Write a description of class Snacks here.
  4. *
  5. * @Drew (your name)
  6. * @1 (a version number or a date)
  7. */
  8. public class Snacks
  9. {
  10. // instance variables - replace the example below with your own
  11.  
  12. /**
  13. * Constructor for objects of class Snacks
  14. */
  15. public Snacks()
  16. {
  17. // Creating an ArrayList of String
  18. ArrayList<String> students = new ArrayList<String>();
  19. int max;
  20. int min;
  21. int randomNum;
  22. // Adding new elements to the ArrayList
  23. students.add("Sameer");
  24. students.add("Praneeth");
  25. students.add("Robert");
  26. students.add("Nishant");
  27. students.add("Michael");
  28. students.add("PeterL");
  29. students.add("Evan");
  30. students.add("William");
  31. students.add("Raunaq");
  32. students.add("Rahul");
  33. students.add("Neil");
  34. students.add("PeterD");
  35. students.add("Jonathan");
  36.  
  37. int listLength = students.size();
  38. String[] list = new String[listLength];
  39.  
  40.  
  41. for(int i = 0; i < listLength; i++){
  42. max = students.size();
  43. min = 0;
  44. randomNum = (int)(Math.random() * ((max - min) )) + min; //exclusive
  45.  
  46. list[i] = students.get(randomNum);
  47. students.remove(randomNum);
  48.  
  49. }
  50.  
  51. for(int f = 0; f < list.length; f++){
  52. System.out.println(list[f]);
  53. }
  54.  
  55. }
  56. }
Add Comment
Please, Sign In to add comment