Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java language. Use boolean, if/else, loop and logic only. No if(true) If it does

ID: 662322 • Letter: J

Question

Java language. Use boolean, if/else, loop and logic only. No if(true) If it doesn't work. I will mark you down.

Write a static method named anglePairs that accepts three angles (integers), measured in degrees, as parameters and returns whether or not there exists both complementary and supplementary angles amongst the three angles passed. Two angles are complementary if their sum is exactly 90 degrees; two angles are supplementary if their sum is exactly 180 degrees. Therefore, the method should return true if any two of the three angles add up to 90 degrees and also any two of the three angles add up to 180 degrees; otherwise the method should return false. You may assume that each angle passed is non-negative.

Here are some example calls to the method and their resulting return values.

Call Value Returned
  anglePairs(0, 90, 180)  anglePairs(45, 135, 45)  anglePairs(177, 87, 3)  anglePairs(120, 60, 30)  anglePairs(35, 60, 30)  anglePairs(120, 60, 45)  anglePairs(45, 90, 45)  anglePairs(180, 45, 45)  
  true  true  true  true  false  false  false  false  

Explanation / Answer

boolean complement(int deg1, int deg2, int deg3)

{

if ((deg1+deg2==90)&&(deg1+deg3==180)

return true;

else if ((deg1+deg2==90)&&(deg2+deg3==180)

return true;

else if ((deg2+deg3==90)&&(deg2+deg1==180)

return true;

else if ((deg1+deg2==90)&&(deg1+deg3==180)

return true;

else if ((deg3+deg1==90)&&(deg2+deg3==180)

return true;

elseif ((deg3+deg1==90)&&(deg1+deg3==180)

return true;

else return false;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote