Created
February 4, 2013 19:19
-
-
Save YounesCheikh/4708868 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.dev.main; | |
import org.dev.MyClass; | |
public class Main { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
Object mysc = MyClass.myFunction(6); | |
System.out.println("Status:"+mysc.getStatus()+"\nCode:"+mysc.getCode()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.dev; | |
import java.util.Random; | |
public class MyClass { | |
public MyClass() { | |
} | |
// My second class returns MySecondClass object | |
public static MySecondClass myFunction(int top) { | |
return new MySecondClass(top); | |
} | |
} | |
class MySecondClass { | |
private String status; | |
private String code; | |
public MySecondClass(int top) { | |
this.status = randString(top); | |
this.code = randString(top); | |
} | |
public String getStatus() { | |
return this.status; | |
} | |
public String getCode() { | |
return this.code; | |
} | |
// Private Method return random string | |
private String randString(int top) { | |
Random ran = new Random(); | |
char data = ' '; | |
String dat = ""; | |
for (int i = 0; i <= top; i++) { | |
data = (char) (ran.nextInt(25) + 97); | |
dat = data + dat; | |
} | |
return dat; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment