Java program and Child Program

Source: Internet
Author: User

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;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.