Question
Hello, I am having an issue with my program. For this program, I am supposed to be utilzing the gale shapley algorithm. The program has
Hello, I am having an issue with my program. For this program, I am supposed to be utilzing the gale shapley algorithm. The program has to be man optimal and written in java. The issue that i am having is that I have a mistake somewhere in my program but i cannot find it. Right now the output of my program will say the correct amount of guys but keeps saying the same woman is matched with them all. I'll include my code down below. Some more information is that I created a class named person and two sub class (boys and girls), boys store their preferences in a linked list meanwhile girls store their preferences in an array. import java.util.*; import java.io.*; public class stable { 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 = 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] = 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
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10 /** 240 */ 4 package Assignment1; 5 60 /** 7 8 9 310 110 /* The person class contains two parameters: 12 * 1.) An integer that will store the associated number of individuals that are being used 13 * within the Gale-Shapely algorithm and when that specific person is introduced. * 15 16 public class person 17 { 318 int name; 019 Boolean inRelationship; 20 210 /* 22 * This constructor will set the name of a person equal to x. 23 */ person(int x) 225 { 226 setName(x); 27 inRelationship = false; 28 } 29 300 /** 31 * @return the name 32 */ 330 public int getName() { 134 return name; 135 } 36 370 /** 38 * @param name the name to set 39 */ $400 public void setName(int name) { 341 this.name = name; } 43 2440 /** 345 * @return the inRelationship 846 */ 3470 public Boolean getInRelationship() { 48 return inRelationship; 49 } 150 151 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 LinkedListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started