Results 1 to 4 of 4
- 09-13-2011, 10:51 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 8
- Rep Power
- 0
StableMatch - Gale Shapley algorithm aka the Stable Marriage
I'm having some trouble getting my StableMatch program to work. Any advice is welcome.
Here's the code in question:
I'm getting Type mismatch: cannot convert from Person<E> to E.
and here's the class codeJava Code:// sets the name of the match for the Person provided public void setMatch(Person<E> name){ match = name; }
Obviously, I'm a fairly novice programmer. Just looking for some help pointing me in the right direction.Java Code:public abstract class Person <E>{ public E match; private String fname; protected List <E> preferences; private String name; // Person Constructor public Person (String aName){ name = aName; } // sets name value for Person public void setName(String aName){ name = aName; } // returns the name of the Person object public String getName(){ return fname; } // returns the name of the Person public String toString(){ if (this.preferences == null) return match.toString(); else return ("" + match.toString() + preferences); } // sets the name of the match for the Person provided public void setMatch(Person<E> name){ match = name; } // gets the match of the Person public E getMatch(){ return match; } // tells whether the Person is available for a match public boolean isAvailable(){ if (this.getMatch() == null) return true; else return false; } // displays the match of the Person public String displayMatch(Person<E> p){ if (p.getMatch() == null){ return p.fname + " is not currently matched"; } else return p.fname + " is matched to "+ this.getMatch(); } public void initializePreferences(List < E > hospitals, int[]hospitalPreferences){ for (int i=0; i < hospitalPreferences.length; i++) preferences.add(hospitals.get(hospitalPreferences[i])); } public void displayPreferences(){ System.out.println(this.name + "'s preferences are:"); Iterator<E> it = preferences.iterator(); while (it.hasNext()) System.out.print("\t" + it.next()); System.out.println(); } public static void main (String args[]){ } }
- 09-13-2011, 11:01 PM #2
Re: StableMatch - Gale Shapley algorithm aka the Stable Marriage
The error message says what the problem is: cannot convert from Person<E> to E.
You have a type mismatch in an assignment statement.
- 09-13-2011, 11:08 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 8
- Rep Power
- 0
Re: StableMatch - Gale Shapley algorithm aka the Stable Marriage
Yeah, I know that the type in the signature is Person <E> (generic) and that the variable "match" is of type E (generic object). Can I cast it or is there something fundamentally wrong with my approach? I want to set the match of the person. Based on my other code do you have any suggestions?
- 09-13-2011, 11:14 PM #4
Similar Threads
-
Stable, Robust Image Files to PDF & HTML to PDF Conversion
By sherazam in forum Java SoftwareReplies: 0Last Post: 04-21-2011, 09:51 AM -
Read Pivot Tables, Shapes in XLSX Files & Stable Excel to PDF Conv.
By sherazam in forum Java SoftwareReplies: 0Last Post: 03-10-2011, 08:34 AM -
Brainbox needed -- KeyEvent VK_* constants stable??!
By Spiller in forum AWT / SwingReplies: 0Last Post: 08-17-2009, 03:59 PM -
Is Java 6 stable?
By bugger in forum New To JavaReplies: 3Last Post: 12-03-2007, 12:12 PM -
Stable Build: Eclipse 3.3M6
By goldhouse in forum Java SoftwareReplies: 0Last Post: 04-02-2007, 02:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks