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...
Write in c++ as simple as possible In a right triangle, the square of the length...
Write in c++ as simple as possible In a right triangle, the square of the length on one side is equal to the sum of the squares of the lengths of the other two sides.  Write a program that prompts the user to enter the length of three sides of the tringle (as doubles) and the outputs a message indication whether the triangle is a right triangle.  You should split this into two functions (but only one .cpp file).  One function is main()...
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 java program for area and perimeter of right triangle
write a java program for area and perimeter of right triangle
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT