Question: Hello, I am currently having an issue with the computer science program that I am writing. While doing the assignment, I am supposed to make
Hello, I am currently having an issue with the computer science program that I am writing. While doing the assignment, I am supposed to make a stable matching of man and woman pairs using the gale shapley algorithm. For the assignment I created a person class and then made two subclasses (boys and girls). The boys class is using a linked list to store their preferences and the girls class is using an array to store their preferences. I also have to represent unmatched men in a stack. I have decided to just create an array called "matchingPairs" that will record which couples are matched together. Currently I am having an issue with my main program, whenever I choose to run my program, I am able to enter the preferences of the individual, but after everything is sorted into a stable matching, I am having an issue where it returns the information in my matchingPairs array as the women being all the same number. I just want to know at what part I am doing this wrong. I have included my main function in the text below and pictures of person, girls, and boys classes.
package Assignment1; import java.util.*; import java.io.*; /** * @author WHEELERJA16 * */
public class stable {
/** * @param args */ public static void main(String[] args) { Scanner matchMaker = new Scanner(System.in); System.out.println(" How many men are being matched this session?"); int max = matchMaker.nextInt(); boys[] boysArray = new boys[max]; girls[] girlsArray = new girls[max]; //This array will store the girls that are matched with a specific guy. The guy will // be reflected using the index of the array. An example of this would be if girl #5 is stored in // index 1, then girl #5 is paired with man #1. int[] matchingPairs = new int[max]; //This for loop will get the preferences of the men from 1 to max. for(int i = 1; i unmatchedGuys = new Stack(); for(int i = max; i >= 1; i--) { unmatchedGuys.push(i); } //This loop will implement the Gale-Shapley Algorithm and produce a stable matching //amongst the soon to be couples. The algorithm will be male optimal. while(unmatchedGuys.empty() == false) { int x = unmatchedGuys.pop(); boys boytestSubject = new boys(x); boytestSubject = boysArray[x - 1]; boytestSubject.inRelationship = false; girls girlTestSubject; LinkedList y = new LinkedList(); y = boytestSubject.getDudesPref(); while(boytestSubject.matchedUp() == false) { int nextPref = y.getFirst(); girlTestSubject = new girls(nextPref, max); girlTestSubject.Galspreferences = girlsArray[nextPref - 1].getGalspreferences(); if(girlTestSubject.galMatchUp() == false) { boytestSubject.statusChange(); girlTestSubject.statusChange(); matchingPairs[boytestSubject.name - 1] = girlTestSubject.name; //Changing the arrays to match what has changed boysArray[boytestSubject.name - 1] = boytestSubject; girlsArray[girlTestSubject.name - 1] = girlTestSubject; } else { int currentHusband = 0; for (int i = 0; i }
}


stable.java Dboys.java X D girls.java person.java CheckingAccount.java 10 /**0 4 package Assignment1; 5 6 import java.util.LinkedList; 7 80 /** 9 * @author WHEELERJA16 19 11 */ 12 public class boys extends person 13 { 14 15 LinkedList dudesPref = new LinkedList(); 16 170 public boys(int x) 18 { 19 super(x); 20 } 210 /** 22 * @return the dudesPref 23 */ 240 public LinkedList getDudesPref() { 25 return dudesPref; 26 } 270 /** 28 * @param dudesPref the dudesPref to set 29 300 public void setDudesPref(int x) { 31 this.dudesPref.add(x); 32 } 33 340 public void statusChange () 35 { 36 this.inRelationship = true; 37 } 38 39 // This class will return the relationship status of any male. 400 public boolean matchedup() 41 { 42 if (this.inRelationship = true) 43 { 144 return true; 45 } 446 return false; 47 } 148 48 4490 public void displayInfo() 50 { 51 System.out.printf("This is guy #%d ", this.name); 52 System.out.printf("His preferences are: "); 53 System.out.println(dudesPref); 54 } 55 } dudesPref = new LinkedList(); 16 170 public boys(int x) 18 { 19 super(x); 20 } 210 /** 22 * @return the dudesPref 23 */ 240 public LinkedList getDudesPref() { 25 return dudesPref; 26 } 270 /** 28 * @param dudesPref the dudesPref to set 29 300 public void setDudesPref(int x) { 31 this.dudesPref.add(x); 32 } 33 340 public void statusChange () 35 { 36 this.inRelationship = true; 37 } 38 39 // This class will return the relationship status of any male. 400 public boolean matchedup() 41 { 42 if (this.inRelationship = true) 43 { 144 return true; 45 } 446 return false; 47 } 148 48 4490 public void displayInfo() 50 { 51 System.out.printf("This is guy #%d ", this.name); 52 System.out.printf("His preferences are: "); 53 System.out.println(dudesPref); 54 } 55 }