Package woman. Ham. Vagina;
Import java. Text. decimalformat;
Import java. util. Random;
Import java. util. collections;
Import java. util. treeset;
/**
*
* @ Author keeny
*
*/
Public class growsonfactory {
Public static final string boy = "boy ";
Public static final string girl = "girl ";
Private Static void product (string sex ){
Man man = man. newinstance ();
Woman woman = woman. newinstance ();
Son myson = NULL;
While (true ){
Myson = join (Man, woman );
Sleeponeyear ();
If (myson. getsex (). Equals (sex ))
Break;
Else
Continue;
}
System. Out. println ("\ n congratulations!" + myson. getsex ());
}
Private Static void sleeponeyear (){
Try {
Thread. Sleep (1000 );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
Private Static son join (man, woman ){
Son son = new son ();
Int strongestsperm = man. getsperm ();
System. Out. println ();
Int strongestovum = woman. getovum ();
If (strongestsperm = strongestovum ){
System. Out. println ("Congratulations! Twins! ");
} Else {
If (strongestsperm + strongestovum) % 2 = 0 ){
Son. setsex (boy );
} Else {
Son. setsex (girl );
}
}
Return son;
}
Private Static string inputsex (){
Required bytes = new bytes (system. In );
String sex = NULL;
If (attributes. hasnext ()){
Sex = rule. Next ();
}
If (sex = NULL ){
System. Out. println ("the input cannot be blank! Re-enter :");
Return inputsex ();
}
If (! Sex. Register signorecase (boy )&&! Sex. inclusignorecase (girl )){
System. Out. println ("Enter gender format error (boy/girl):" + sex + "re-input :");
Return inputsex ();
}
Return sex;
}
Public static void main (string [] ARGs ){
System. Out. println ("Please select the desired gender (boy/girl ):");
String sex = inputsex ();
Growsonfactory. Product (sex );
}
}
Class man {
Public static decimalformat format = new decimalformat ("0.0000 ");
Public static man newinstance (){
Return New Man ();
}
Public int getsperm (){
Treeset <integer> sperms = new treeset <integer> ();
Double maxsperm = new random (). nextint (integer. max_value/10000 );
For (INT I = 1; I <maxsperm + 1; I ++ ){
System. Out. Print ("\ rIn sex ..."
+ Format. Format (I/maxsperm) * 100) + "% \ t" + I + "/"
+ (INT) maxsperm );
Sperms. Add (new random (). nextint (I ));
}
Return sperms. Last ();
}
}
Class woman {
Public static decimalformat format = new decimalformat ("0.0000 ");
Public static woman newinstance (){
Return New Woman ();
}
Public int getovum (){
Treeset <integer> sperms = new treeset <integer> ();
Double maxovum = new random (). nextint (integer. max_value/10000 );
For (INT I = 1; I <maxovum + 1; I ++ ){
System. Out. Print ("\ rIn sex ..."
+ Format. Format (I/maxovum) * 100) + "% \ t" + I + "/"
+ (INT) maxovum );
Sperms. Add (new random (). nextint (I ));
}
Return sperms. Last ();
}
}
Class son {
Private string sex;
Public String getsex (){
Return sex;
}
Public void setsex (string sex ){
This. Sex = sex;
}
}