Question

In: Computer Science

(In Java) Write three static functions that each take two double values which represent the two...

(In Java) Write three static functions that each take two double values which represent the two smaller sides of a right triangle. The first will calculate and return the area of the triangle, the second will calculate and return the length of the hypotenuse and the third will calculate and return the perimeter of the triangle. (Note: to calculate the perimeter, you need the value of the hypotenuse, so you must be calling that method from inside the other method.) You will also create a main method to ask the user to give the two inputs for a triangle. Then report the results of calls to the three methods. Important: None of these methods should output the results to the screen, all input and output should be done in the main. Additionally the user should be allowed to input multiple sets of data until they decide that they are finished.

Solutions

Expert Solution

if something does not work, just drop a comment;

the required methods are given as follows:

//-------------------

public static void main(String[] args) {

        Scanner scanner=new Scanner(System.in);

        double a;

        double b;

        //loops infinitely

        while(true){

            System.out.println("enter the length of the first side");

            a=scanner.nextDouble();

            System.out.println("enter the length of the second side");

            b= scanner.nextDouble();

            System.out.println("Area: "+getArea(a, b));

            System.out.println("Hypoteneuse length: "+getHypot(a, b));

            System.out.println("perimeterer: "+getPerimeter(a, b));

            System.out.println("");

        }


  }

    static double getHypot(double a, double b){

        //using the pythagorus theorem

        return Math.sqrt((a*a) +(b*b));

    }

    static double getPerimeter(double a, double b){

        //the sum of all sides

        return (a+b+getHypot(a, b));

    }

    static double getArea(double a, double b){

        //using the area formula

        return 0.5*(a*b);

    }


Related Solutions

Java Question: Write three static functions that each take two double values which represent the two...
Java Question: Write three static functions that each take two double values which represent the two smaller sides of a right triangle. The first will calculate and return the area of the triangle, the second will calculate and return the length of the hypotenuse and the third will calculate and return the perimeter of the triangle. (Note: to calculate the perimeter, you need the value of the hypotenuse, so you must be calling that method from inside the other method.)...
Java please. Write a static method sqrt()that takes a double argument and returns the square root...
Java please. Write a static method sqrt()that takes a double argument and returns the square root of that number using newton's method to compute result.
Write a generic method in java code public static double jaccard(HashSet A, HashSet B) that on...
Write a generic method in java code public static double jaccard(HashSet A, HashSet B) that on input two sets represented as hash sets, returns their Jaccard similarity. The following are a few sample runs: Input :    A=1, 2, 3, 4,   B=2, 4, 6, 8 Return:   0.3333333333333333 Input :    A=Larry, Michael, Shaq, Kobe, LeBron                    B=Steve, Kobe, Shaq, LeBron, Steph, Jeremy, Michael Return:   0.5 Your method must have time complexity On and space complexity O1, where n is the size of...
In this homework assignment, you will be writing three `void` functions. These functions each take a...
In this homework assignment, you will be writing three `void` functions. These functions each take a single integer parameter. The functions accomplish the following tasks. * The first function prints out the sum of the numbers from 1 up to and including the number passed to it as an argument. * The second function prints out the sum of the even numbers from 2 up to and including the number passed to it as an argument. * The third function...
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
Recursion practice Write a Java program with functions for each of the following problems. Each problem...
Recursion practice Write a Java program with functions for each of the following problems. Each problem should be solved by writing a recursive function. Your final program should not have any loops in it. All of your solutions should be in a single .java file. The main function of the file should demonstrate each of your solutions, by running several tests and producing the corresponding outputs. Write a recursive method to 1. calculate power of a give number 2. multiply...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate,...
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also...
Write a java method to swap between two values in a singly linked list
Write a java method to swap between two values in a singly linked list
1. Write a class Compare3 that provides a static method largest. Method largest should take three...
1. Write a class Compare3 that provides a static method largest. Method largest should take three Comparable parametersand return the largest of the three (so its return type will also be Comparable). Recall that method compareTo is part ofthe Comparable interface, so largest can use the compareTo method of its parameters to compare them. 2. Write a class Comparisons whose main method tests your largest method above. •   First prompt the user for and read in three strings, use your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT