/** * FILE: Woman.java * AUTHOR: Ivan J Leichtling * INERNET: ivan@columbia.edu * * This file defines a Woman, an extension of the person class with the ability * to be proposed to, to accept and reject lists of proposals for marraige. */ import java.io.* ; import java.util.* ; import java.awt.* ; public class Woman extends Person { protected Vector vSuitors; public Woman( String sNomen, TextArea ta ) { super( sNomen, ta ); i_Sex = Person.FEMALE; vSuitors = new Vector(); } public Enumeration getProposals() { return( vSuitors.elements() ); } /* Called initially by a suitor */ public void askToMarry( Man man ) { vSuitors.addElement( man ); } public void decide() { Man man; if( 0 == vSuitors.size() ) { /* she's ugly */ return; } if( !getEngaged() ) { man = (Man) vSuitors.elementAt( 0 ); vSuitors.removeElementAt( 0 ); } else { man = (Man) getFiancee(); } Enumeration e = vSuitors.elements(); while( e.hasMoreElements() ) { Man otherGuy = (Man) e.nextElement(); if( vPreferences.indexOf(otherGuy) < vPreferences.indexOf( man ) ) { if( man != (Man) getFiancee() ) { man.reject(); } else { print( new BetterGuy( getName(), otherGuy.getName(), getFiancee().getName() ).toString() ); getFiancee().dump(); setFiancee( null ); setEngaged( false ); } man = otherGuy; } else { otherGuy.reject(); } } if( man != (Man)getFiancee() ) { setFiancee( man ); setEngaged( true ); print( new AcceptGuy( getName(), getFiancee().getName() ).toString() ); man.accept( this /* ME */ ); } vSuitors = new Vector(); } public boolean hasSuitors() { return( ( 0 < vSuitors.size() ) ? true : false ); } }