mercredi 2 septembre 2020

Is there a way to use the code for OutOfOrder, to make InOrder as simple as OutOfOrder?

I have having a hard time trialling methods using ONLY the rules of logic and using the OutOfOrder code, to make InOrder as simple as OurOfOrder.

public class InOrder {
//Don't change this
public boolean OutOfOrder(int n1, int n2, int n3) {
return (n1 > n2) || (n2 > n3);
}

//The original and messy InOrder, leave this as an example of what not to do
public boolean inOrder(int n1, int n2, int n3) {
if (n2 > n1) {
  if (n3 > n2) {
    return true;
  } else {
    return false;
  }
} else if (n2 == n1) {
  if (n3 == n1) {
    return true;
  } else {
    return false;
  }
} else {
  return false;
}
}

//The new and improved InOrder for part 5, call OutOfOrder
public boolean inOrder5a(int n1, int n2, int n3) {
return true; //replace this
}

//The newer and improved InOrder for part 6, inline
public boolean inOrder5b(int n1, int n2, int n3) {
return true;//replace this
}

}

Aucun commentaire:

Enregistrer un commentaire