(a). Write code for a method makeOrderedUp1. The method receives a reference to
ID: 3773389 • Letter: #
Question
(a). Write code for a method makeOrderedUp1. The method receives a reference to a pairOfInts object (pair). It returns a reference to a PairOfInts object whose instance variables contain the same values as pair where the value of int1 is always less than or equal to the value int2.
(b). Write code for a method makeOrderedUp2. The method receives a reference to a pairOfInts object (pair). If the instance variables of pair are such that the value of int1 is less than the value of int2. It will change each value such that pair will contain the same values of its instance variables such that now the value of int1 will be less than or equal to the value of int2.
Explanation / Answer
a) PairOfInts makeOrderedUp1(PairOfInts pairOfInts){
if(pairOfInts.int1<=pairOfInts.int2){
return pairOfInts;
}
return null;
}
b) PairOfInts makeOrderedUp2(PairOfInts pairOfInts){
if(pairOfInts.int1<pairOfInts.int2){
return pairOfInts;
}
return null;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.