Help with voting system.

Discussion in 'Plugin Development' started by hayhaycrusher, Aug 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    hayhaycrusher

    So i have 4 lists
    Code:java
    1. List<String> map1 = new ArrayList();
    2. List<String> map2 = new ArrayList();
    3. List<String> map3 = new ArrayList();
    4. List<String> map4 = new ArrayList();


    How would i compare all of theses lists and get the biggest list, as in .size()

    Bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    Pizza371

    Compare each one to eachother? hayhaycrusher it may take a little while but..
     
  3. Offline

    hayhaycrusher


    Pizza371 im doing a voting system, and i want to get the map with the most votes, so get the list with the most votes.
     
  4. Offline

    Pizza371

    What if two maps are the same?
    E.G.
    Code:
    if(map1.size() > map2.size() && map1.size() > map3.size() .. etcetera {
    //dostuff?
    }
    hayhaycrusher
     
  5. Offline

    hayhaycrusher


    if 2 maps are the same, i'll try have it so if map1 and map2 are the same, map1 would get the priority.

    sam with if map3 and 4 are the same, map3 will be chosen.

    so how would i go about doing this.
     
  6. Offline

    the_ceed

    Code:java
    1. int[] maps = {map1.size(), map2.size(), map3.size(), map4.size()};
    2.  
    3. public int findLargest(int[] numbers){
    4. int largest = numbers[0];
    5. for(int i = 1; i < numbers.length; i++){
    6. if(numbers > largest){
    7. largest = numbers;
    8. }
    9. }
    10. return largest;
    11. }
    12.  
    13. System.out.println(findLargest(maps) + " is the largest");


    That should find the largest number but won't tell you which map it is. If you want to find which map it is simply check what map.size() is equal to the largest.
     
  7. Offline

    hayhaycrusher

    Pizza371 dw i know :p


    the_ceed
    That way i wont be able to check if 2 maps equal the same.

    @Pizza371
    this should cover every different outcome right, if so thats all i need to do.
    Code:java
    1. //if map1 is the biggest
    2. if((map1.size() > map2.size()) && (map1.size() > map3.size()) && (map1.size() > map4.size())){
    3.  
    4. }
    5. //if map2 is the biggest
    6. if((map2.size() > map1.size()) && (map2.size() > map3.size()) && (map2.size() > map4.size())){
    7.  
    8. }
    9. //if map3 is the biggest
    10. if((map3.size() > map1.size()) && (map3.size() > map2.size()) && (map3.size() > map4.size())){
    11.  
    12. }
    13. //if map4 is the biggest
    14. if((map4.size() > map1.size()) && (map4.size() > map3.size()) && (map4.size() > map2.size())){
    15.  
    16. }
    17.  
    18. //if map1 and 2 are the same
    19. if((map1.size() == map2.size()) && (map1.size() > map3.size()) && (map1.size() > map4.size()) && (map2.size() > map3.size()) && (map2.size() > map4.size())){
    20.  
    21. }
    22. //if map1 and 3 are the same
    23. if((map1.size() == map3.size()) && (map1.size() > map2.size()) && (map1.size() > map4.size()) && (map3.size() > map2.size()) && (map3.size() > map4.size())){
    24.  
    25. }
    26. //if map1 and 4 are the same
    27. if((map1.size() == map4.size()) && (map1.size() > map2.size()) && (map1.size() > map3.size()) && (map4.size() > map2.size()) && (map4.size() > map3.size())){
    28.  
    29. }
    30. //if map2 and 3 are the same
    31. if((map2.size() == map3.size()) && (map2.size() > map1.size()) && (map2.size() > map4.size()) && (map3.size() > map1.size()) && (map3.size() > map4.size())){
    32.  
    33. }
    34. //if map2 and 4 are the same
    35. if((map2.size() == map4.size()) && (map2.size() > map1.size()) && (map2.size() > map3.size()) && (map4.size() > map1.size()) && (map4.size() > map3.size())){
    36.  
    37. }
    38. //if map3 and 4 are the same
    39. if((map3.size() == map4.size()) && (map3.size() > map1.size()) && (map3.size() > map2.size()) && (map4.size() > map1.size()) && (map4.size() > map2.size())){
    40.  
    41. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  8. Offline

    Pizza371

    hayhaycrusher Check if they == the same too? So you can do what you said above? sorry i had to afk a sec
    EDIT: i just looked at the first line and assumed.. lol glad you got it fixed
     
  9. Offline

    hayhaycrusher

    Pizza371
    Just realized theres more combinations :)

    Code:java
    1. //if map1, 2 and 3 are the same
    2. if((map1.size() == map2.size()) && (map2.size() == map3.size()) && (map1.size() > map4.size()) && (map2.size() > map4.size()) && (map3.size() > map4.size())){
    3.  
    4. }
    5. //if map1, 2 and 4 are the same
    6. if((map1.size() == map2.size()) && (map2.size() == map4.size()) && (map1.size() > map3.size()) && (map2.size() > map3.size()) && (map4.size() > map3.size())){
    7.  
    8. }
    9. //if map2, 3 and 4 are the same
    10. if((map2.size() == map3.size()) && (map3.size() == map4.size()) && (map2.size() > map1.size()) && (map3.size() > map1.size()) && (map4.size() > map1.size())){
    11.  
    12. }
    13. //if map1, 3 and 4 are the same
    14. if((map1.size() == map3.size()) && (map3.size() == map4.size()) && (map1.size() > map2.size()) && (map3.size() > map2.size()) && (map4.size() > map2.size())){
    15.  
    16. }
    17. //if all the maps are the same
    18. if((map1.size() == map3.size()) && (map3.size() == map4.size()) && (map4.size() == map2.size())){
    19.  
    20. }


    That should do it.
     
  10. Offline

    Pizza371

    hayhaycrusher yup haha. It can get pretty annoying and confusing sometimes with things like this :p
     
Thread Status:
Not open for further replies.

Share This Page