fork download
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3.  
  4. public class Main {
  5.  
  6.  
  7. ArrayList<Person> personList = new ArrayList<Person>();
  8. void init(){
  9.  
  10. //Adding persons to the list
  11.  
  12. personList.add(new Person("Tesan de Boer", "Straatweg 45", 2222));
  13. personList.add(new Person("Peter Post", "Straatweg 45", 2222, 1));
  14. personList.add(new Person("piet puk", "Straatweg 45", 2222, 21));
  15. personList.add(new Person("Siem van Aanhoolt", "Straatweg 45", 2222, 31));
  16. personList.add(new Person("Denis van rijn", "Straatweg 45", 2222, 5));
  17. personList.add(new Person("Koen Weegink", "Straatweg 45", 2222, 2));
  18. personList.add(new Person("Jan-Willem Rufus op den Haar", "Straatweg 45", 2222, 3));
  19. personList.add(new Person("Tom Kraniker", "Straatweg 45", 2222, 4));
  20. personList.add(new Person("Leon het Kanon", "Straatweg 45", 2222, 6));
  21. personList.add(new Person("Robin Hogezant", "Straatweg 45", 2222, 7));
  22. personList.add(new Person("Loesoe de Kat", "Straatweg 45", 2222, 8));
  23. personList.add(new Person("Morris de Spee", "Straatweg 45", 2222, 9));
  24. personList.add(new Person("Rein Zoekers", "Straatweg 45", 2222, 10));
  25. personList.add(new Person("Darion Pok", "Straatweg 45", 2222, 11));
  26. personList.add(new Person("Achmed de Bom", "Straatweg 45", 2222, 12));
  27. }
  28.  
  29. public void randomCaptain(){
  30. Random dice = new Random ();
  31. int n = dice.nextInt(personList.size());
  32. Person theCaptain = personList.get(n);
  33. System.out.println(theCaptain);
  34. }
  35.  
  36. public static void main(String args[] ) {
  37. Main team= new Main();
  38. team.init();
  39. team.randomCaptain();
  40. }
  41.  
  42. public static class Person {
  43. String _name;
  44. String _team;
  45. int _code1;
  46. int _code2;
  47.  
  48. Person(String name, String team, int code1) {
  49. this(name, team, code1, -1);
  50. }
  51. Person(String name, String team, int code1, int code2) {
  52. _name = name;
  53. _team = team;
  54. _code1 = code1;
  55. _code2 = code2;
  56. }
  57.  
  58. public String toString() {
  59. return "[" + _name + ";" + _team + ";" + _code1 + ";" + _code2 + "]";
  60. }
  61. }
  62. }
  63.  
  64.  
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
[Peter Post;Straatweg 45;2222;1]