Win a copy of Head First Agile this week in the Agile forum!
    Bookmark Topic Watch Topic
  • New Topic

I am trying to randomly generate men's preference list and women's preference list on StableMarriage  RSS feed

 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
here is my code
please help me to generate code
i dont know how to use map string list
line number 31 to 34


package stablemarriage;
import java.util.*;
 
public class StableMarriage {
 
    public static void main(String[] args){
        
        int list;
        //int value = 0;
        
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Gale Shapley Marriage Algorithm\n");
    System.out.print("The number of marriages? ");
    list = keyboard.nextInt();
        
    LinkedList<String> men = new LinkedList<>();
    LinkedList<String> women = new LinkedList<>();
        for (int i = 0; i < list; i++)
        {
            men.add("Man-"+(i+1));                   
            women.add("Woman-"+(i+1));
            System.out.print(men.get(i)+" ~ ");
            System.out.println(women.get(i));
        }
        
        Map<String, List<String>> manPref = new HashMap<String, List<String>>();
        Map<String, List<String>> womanPref = new HashMap<String, List<String>>();
        for (int i = 0; i < list; i++)
        {
        Collections.shuffle(men);
        Collections.shuffle(women);
        manPref.put(men.get(i), array);
        womanPref.put(key, women);
        }
        for(String str: men){
            System.out.print(str+" ");
        }
        System.out.println();

         for(String str: women){
            System.out.print(str+" ");
        }
         System.out.println();
    }

something like this /**/static List<String> guys = Arrays.asList(
            new String[]{
        "M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10"});
    static List<String> girls = Arrays.asList(
            new String[]{
        "W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8", "W9", "W10"});
    static Map<String, List<String>> guyPrefers =
            new HashMap<String, List<String>>(){{
        put("M1",
            Arrays.asList("W1", "W5", "W3", "W9", "W10", "W4", "W6",
            "W2", "W8", "W7"));
        put("M2",
            Arrays.asList("W3", "W8", "W1", "W4", "W5", "W6", "W2",
            "W10", "W9", "W7"));
        put("M3",
            Arrays.asList("W8", "W5", "W1", "W4", "W2", "W6", "W9",
            "W7", "W3", "W10"));
        put("M4",
            Arrays.asList("W9", "W6", "W4", "W7", "W8", "W5", "W10",
            "W2", "W3", "W1"));
        put("M5",
            Arrays.asList("W10", "W4", "W2", "W3", "W6", "W5", "W1",
            "W9", "W8", "W7"));
        put("M6",
            Arrays.asList("W2", "W1", "W4", "W7", "W5", "W9", "W3",
            "W10", "W8", "W6"));
        put("M7",
            Arrays.asList("W7", "W5", "W9", "W2", "W3", "W1", "W4",
            "W8", "W10", "W6"));
        put("M8",
            Arrays.asList("W1", "W5", "W8", "W6", "W9", "W3", "W10",
            "W2", "W7", "W4"));
        put("M9",
            Arrays.asList("W8", "W3", "W4", "W7", "W2", "W1", "W6",
            "W9", "W10", "W5"));
       
        put("M10",
            Arrays.asList("W1", "W6", "W10", "W7", "W5", "W2", "W4",
            "W3", "W9", "W8"));
    }};
    static Map<String, List<String>> girlPrefers =
            new HashMap<String, List<String>>(){{
        put("W1",
            Arrays.asList("M2", "M6", "M10", "M7", "M9", "M1", "M4",
            "M5", "M3", "M8"));
        put("W2",
            Arrays.asList("M2", "M1", "M3", "M6", "M7", "M4", "M9",
            "M5", "M10", "M8"));
        put("W3",
            Arrays.asList("M6", "M2", "M5", "M7", "M8", "M3", "M9",
            "M1", "M4", "M10"));
        put("W4",
            Arrays.asList("M6", "M10", "M3", "M1", "M9", "M8", "M7",
            "M4", "M2", "M5"));
        put("W5",
            Arrays.asList("M10", "M8", "M6", "M4", "M1", "M7", "M3",
            "M5", "M9", "M2"));
        put("W6",
            Arrays.asList("M2", "M1", "M5", "M9", "M10", "M4", "M6",
            "M7", "M3", "M8"));
        put("W7",
            Arrays.asList("M10", "M7", "M8", "M6", "M2", "M1", "M3",
            "M5", "M4", "M9"));
        put("W8",
            Arrays.asList("M7", "M10", "M2", "M1", "M9", "M4", "M8",
            "M5", "M3", "M6"));
        put("W9",
            Arrays.asList("M9", "M3", "M8", "M7", "M6", "M2", "M1",
            "M5", "M10", "M4"));
        put("W10",
            Arrays.asList("M5", "M8", "M7", "M1", "M2", "M10", "M3",
            "M9", "M6", "M4"));/**/
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post, essentially the same question multiple times. Let us continue the discussion in your original topic here https://coderanch.com/t/670306/java/java/generate-men-preference-list-women
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!