Question

In: Computer Science

Write class Hypotenuse that calculates the length of the hypotenuse of a right triangle and return...

Write class Hypotenuse that calculates the length of the hypotenuse of a right triangle and return to HypotenuseTest class. The lengths of the other two sides are given by the user by using HypotenuseTest class and send into Hypotenuse class. Hypotenuse class should
take two arguments of type double and return the hypotenuse as a double into HypotenuseTest’s Main method. Finally, the HypotenuseTest class displays the hypotenuse side of a triangle.

Solutions

Expert Solution

import java.lang.Math;

public class Hypotenuse {

    double length;

    double breadth;

    Hypotenuse(double length,double breadth)

    {

        this.length=length;

        this.breadth=breadth;

    }

    public double getHypo()

    {

        return(Math.pow(length*length+breadth*breadth, 0.5));

    }

}


import java.util.Scanner;

class HypotenuseTest{

    public static void main(String[] args) {

        double length,breadth;

        int choice;

        Scanner sc=new Scanner(System.in);

        while(true)

        {

            System.out.println("1.Get hypotenuse");

            System.out.println("2.Exit");

            System.out.print("Enter your choice:");

            choice=sc.nextInt();

            switch (choice) {

                case 1:

                    System.out.print("Enter length of a right triangle:");

                    length=sc.nextDouble();

                    System.out.print("Enter breadth of a right triangle:");

                    breadth=sc.nextDouble();

                    Hypotenuse obj=new Hypotenuse(length, breadth);

                    System.out.printf("Hypotenuse of a rigth triangle is %f\n", obj.getHypo());

                    break;

                case 2:

                    System.exit(0);

            

                default:

                    break;

            }

        }

    }

}


Related Solutions

Find the lengths of the arms of a right triangle whose hypotenuse has length c if...
Find the lengths of the arms of a right triangle whose hypotenuse has length c if these arms have a ratio of (a) 3;4 and c=15, (b) 5;12 and c=26, (c) 8;15 and c =170 and (d) 1;2 and c=10
Related rates Part A: 1. Consider a right triangle with hypotenuse of (fixed) length 46 cm...
Related rates Part A: 1. Consider a right triangle with hypotenuse of (fixed) length 46 cm and variable legs of lengths x and y, respectively. If the leg of length x increases at the rate of 6 cm/min, at what rate is y changing when x = 5 cm? (Round your answer to three decimal places.) 2. Water is flowing into a vertical cylindrical tank of diameter 8 m at the rate of 5 m3/min. Find the rate at which...
An isosceles right triangle, whose hypotenuse is 12 ft long, is submerged vertically so that the...
An isosceles right triangle, whose hypotenuse is 12 ft long, is submerged vertically so that the hypotenuse is parallel to the surface of the water. If its vertex is 3 ft above the surface, find the total force on one side of the plate?
A right triangle whose hypotenuse is √18 m long is revolved about one of its legs...
A right triangle whose hypotenuse is √18 m long is revolved about one of its legs to generate a right circular cone. Find the​ radius, height, and volume of the cone of greatest volume that can be made this way.
What is the length of the hypotenuse in the image below?
What is the length of the hypotenuse in the image below? Round your answer to 1 decimal place, units not required.
Given a right triangle with one leg length of a, one leg length of x-3 and...
Given a right triangle with one leg length of a, one leg length of x-3 and the hypo is x, how does a affect x? Shown on a graph. I solved for a, it is equal to the square root of 6x-9.... I am having a difficult time interpreting how a affects x.. I am not sure how to graph
Java Write a class called Triangle that can be used to represent a triangle. Write a...
Java Write a class called Triangle that can be used to represent a triangle. Write a class called Describe that will interface with the Triangle class The Server • A Triangle will have 3 sides. It will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. • It will allow a client to create a Triangle, passing in integer values for the...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2 Codes in C please.s
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT