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

Write a class called Pythagoras, such that given two values x and y, where x rep

ID: 3623827 • Letter: W

Question


Write a class called Pythagoras, such that given two values x and y, where x represents the length of the ladder, and y represents the distance the foot of the ladder is from the ground, calculates the height of the house, and also the angle between the ladder and the ground. In your design, include a mutator method that calculates both values. Write appropriate constructor(s), and accessor methods to return each value.

Recall:
• The formula for the Pythagoras Theorem is: a2 + b2 = c2, and,
• The cosine formula to find the angle (in radians), cosine A = distance on the ground/length of the ladder. Give the answer in degrees.

• Write a class to test your class Pythagoras.
• Use the class GetData.java to enter the data.
• Place your output in a scrollable pane.

Explanation / Answer

class GetData
{
private int x;   // length of ladder
private int y;   // distance the foot of the ladder is from the ground
GetData()
{
    x = 13;
    y = 5;
}

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}
public class Pythagoras {

   public static double HouseHeight(int a,int b)
   {
       return Math.sqrt(a*a-b*b);
   }
    public static void main(String[] args) {
        GetData gd = new GetData();
        double h = HouseHeight(gd.getX(),gd.getY());
        System.out.println("House Height is given by :" + h);
        System.out.println("Angle is given by :" + Math.acos((double)gd.getY()/gd.getX()) * 180/Math.PI);
    }

}

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