Help rewriting constructors!!

Can anyone help me rewrite these constructors to be less repetitive!?

public Q (String s){

String rational[] = s.split("/");

Z numz, denomz;

if(rational.length == 1){

numz =new Z(rational[0]);

denomz = Z.ONE;

}

else{

if(rational.length == 2){

numz =new Z(rational[0]);

denomz =new Z(rational[1]);

}

else{

thrownew RuntimeException("Cannot make a Q from " + s);

}

}

if(denomz.equals(Z.ZERO)){

this.num = Z.UNDEFINED;

this.denom = Z.UNDEFINED;

}

else{

if(numz.equals(Z.ZERO)){

this.num = Z.ZERO;

this.denom = Z.ONE;

}

else

{

Z gcd = numz.gcd(denomz);

numz = numz.dividedBy(gcd);

denomz = denomz.dividedBy(gcd);

if(!(denomz.sign() == numz.sign()))

{

numz =new Z(-1, numz.magnitude());

denomz =new Z(1, denomz.magnitude());

}

this.num = numz;

this.denom = denomz;

}

}

}

public Q(Z numz, Z denomz){

if(denomz.equals(Z.ZERO)){

this.num = Z.UNDEFINED;

this.denom = Z.UNDEFINED;

}

else{

if(numz.equals(Z.ZERO)){

this.num = Z.ZERO;

this.denom = Z.ONE;

}

else{

Z gcd = numz.gcd(denomz);

numz = numz.dividedBy(gcd);

denomz = denomz.dividedBy(gcd);

if(!(denomz.sign() == numz.sign())){

numz =new Z(-1, numz.magnitude());

denomz =new Z(1, denomz.magnitude());

}

this.num = numz;

this.denom = denomz;

}

}

}

[3304 byte] By [germans88a] at [2007-11-26 19:38:49]
# 1
Don't cross-post: http://forum.java.sun.com/thread.jspa?threadID=5141130Kaj
kajbja at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...
# 2
Plase don't cross post. Stick with the following thread: http://forum.java.sun.com/thread.jspa?threadID=5141130&tstart=0Posters, please post answers there.Edit: Man I am even too slow for this sort of thing.
masijade.a at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...
# 3

public Con(String s){

//convert string to nom and denom here

shortcut(nom, denom);

}

public Con(int nom, int denom){

shortcut(nom, denom);

}

private void shortcut(int nom, int denom){

//repetitive codes here

}

what i'm gonna do I didn't know it was a cross post T.T

Message was edited by:

Icycool

Icycoola at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...
# 4

public Q (String s) {

String rational[] = s.split("/");

Z numz, denomz;

if(rational.length == 1){

numz = new Z(rational[0]);

denomz = Z.ONE;

}

else {

if(rational.length == 2){

numz = new Z(rational[0]);

denomz = new Z(rational[1]);

}

else {

throw new RuntimeException("Cannot make a Q from " + s);

}

}

this(numz,denomz);

}

public Q(Z numz, Z denomz) {

if(denomz.equals(Z.ZERO)) {

this.num = Z.UNDEFINED;

this.denom = Z.UNDEFINED;

}

else {

if(numz.equals(Z.ZERO)) {

this.num = Z.ZERO;

this.denom = Z.ONE;

}

else {

Z gcd = numz.gcd(denomz);

numz = numz.dividedBy(gcd);

denomz = denomz.dividedBy(gcd);

if(!(denomz.sign() == numz.sign())) {

numz = new Z(-1, numz.magnitude());

denomz = new Z(1, denomz.magnitude());

}

this.num = numz;

this.denom = denomz;

}

}

}

Vishwas_Prasannaa at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...
# 5
> what i'm gonna do I didn't know it was a cross postJust post your answer in the other thread and let this one die.Kaj
kajbja at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...
# 6
@Vishwas_Prasanna. Post in the other thread. ...and your answer doesn't work. A constructor call (using this) must be first in the constructor.Kaj
kajbja at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...
# 7
Thanks Kaj for finding out the error. And i am really sorry "germans88 " to misguide you.
Vishwas_Prasannaa at 2007-7-9 22:17:21 > top of Java-index,Java Essentials,New To Java...