Question

In: Computer Science

Program Specifications The built-in Java Math methods make some calculations much easier. Write a program called...

Program Specifications

The built-in Java Math methods make some calculations much easier. Write a program called "DoTheMath" that accepts as input three floating-point numbers x, y, and z (define them as double) and outputs several calculations:

  1. x to the power of y
  2. x to the power of (y to the power of z)
  3. The absolute value of x
  4. The square root of (x*y to the power of z).

Sample Run:

Enter the values for x, y, z:
-3.7 -3 5
 <-- print a blank line before outputting calculations
x to the power y is -0.019742167295125655
x to the power y to the power z is -8.452419664263233E-139
The absolute value of x is 3.7
The square root of x*y to the power z is 410.49459863681534 <-- end with a println

honestly just kind of lost on how to do this.

Solutions

Expert Solution

import java.util.Scanner;

public class DoTheMath {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the values for x, y, z:");
        double x = in.nextDouble();
        double y = in.nextDouble();
        double z = in.nextDouble();
        //  <-- print a blank line before outputting calculations
        System.out.println();
        // x to the power y is -0.019742167295125655
        System.out.println("x to the power y is " + Math.pow(x, y));
        // x to the power y to the power z is -8.452419664263233E-139
        System.out.println("x to the power y to the power z is " + Math.pow(x, Math.pow(y, z)));
        // The absolute value of x is 3.7
        System.out.println("The absolute value of x is " + Math.abs(x));
        // The square root of x*y to the power z is 410.49459863681534 <-- end with a println
        System.out.println("The square root of x*y to the power z is " + Math.sqrt(Math.pow(x*y, z)));
    }
}


Related Solutions

Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a...
Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a title Ask the user to enter the following values: The type of plane(Boeing 747 or Airbus A300) The number of passengers on board the Plane The number of crew aboard the plane The maximum number of people that can be carried by one liferaft assuming all the liferafts on the plane are the same size The actual number of liferafts that are available on...
Write a program in Java and run it in BlueJ according to the following specifications: The...
Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line) and determines their type (excellent or ok). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "all" - prints all student records (first name, last name, grade, type). "excellent" - prints students with grade > 89. "ok"...
Write a JAVA program called Convertor that has two methods. The first one converts an input...
Write a JAVA program called Convertor that has two methods. The first one converts an input binary into its equivalent decimal number. The second method converts a decimal number into its equivalent binary.​ binary2Decimal, decimal2Binary are the names for those methods.​ binary2Decimal receives a binary number as a string and returns a decimal number as an integer. And vice versa for the decimal2Binary method.​
in Java, write a program for methods (Secant, False-Position and Modified Secant) for locating roots. Make...
in Java, write a program for methods (Secant, False-Position and Modified Secant) for locating roots. Make sure that you have clever checks in your program to be warned and stop if you have a divergent solution or stop if the solution is very slowly convergent after a maximum number of iterations. (a) f(x) = 2x3 – 11.7x2 + 17.7x – 5 This function has 3 +ve roots, all of which lie between 0 and 4. Find the roots. Implement the...
write a program to make scientific calculator in java
Problem StatementWrite a program that uses the java Math library and implement the functionality of a scientific calculator. Your program should have the following components:1. A main menu listing all the functionality of the calculator.2. Your program should use the switch structure to switch between various options of the calculator. Your Program should also have the provision to handle invalidoption selection by the user.3. Your calculator SHOULD HAVE the following functionalities. You can add any other additional features. PLEASE MAKE...
Create a Java application that meets the following specifications. Write whatever public and private methods are...
Create a Java application that meets the following specifications. Write whatever public and private methods are necessary. Put all of these classes in a package called persistence1. Student has a String name, a double GPA, and a reasonable equals() method. Course has a String name, an ArrayList of Students, and a reasonable equals() method. It will also need a method to add a Student. StudentPersister uses binary file I/O to save and retrieve Students and Lists of Students. CoursePersister does...
IN JAVACreate a Java application that meets the following specifications. Write whatever public and private methods...
IN JAVACreate a Java application that meets the following specifications. Write whatever public and private methods are necessary. Put all of these classes in a package called persistence1. Student has a String name, a double GPA, and a reasonable equals() method. Course has a String name, an ArrayList of Students, and a reasonable equals() method. It will also need a method to add a Student. StudentPersister uses binary file I/O to save and retrieve Students and Lists of Students. CoursePersister...
IN JAVACreate a Java application that meets the following specifications. Write whatever public and private methods...
IN JAVACreate a Java application that meets the following specifications. Write whatever public and private methods are necessary. Put all of these classes in a package called persistence1. Student has a String name, a double GPA, and a reasonable equals() method. Course has a String name, an ArrayList of Students, and a reasonable equals() method. It will also need a method to add a Student. StudentPersister uses binary file I/O to save and retrieve Students and Lists of Students. CoursePersister...
Create a Java application that meets the following specifications. Write whatever public and private methods are...
Create a Java application that meets the following specifications. Write whatever public and private methods are necessary. Put all of these classes in a package called persistence1. The student has a String name, a double GPA, and a reasonable equals() method. The course has a String name, an ArrayList of Students, and a reasonable equals() method. It will also need a method to add a Student. StudentPersister uses the binary file I/O to save and retrieve Students and Lists of...
Create a Java application that meets the following specifications. Write whatever public and private methods are...
Create a Java application that meets the following specifications. Write whatever public and private methods are necessary. Put all of these classes in a package called persistence1. The student has a String name, a double GPA, and a reasonable equals() method. The course has a String name, an ArrayList of Students, and a reasonable equals() method. It will also need a method to add a Student. StudentPersister uses the binary file I/O to save and retrieve Students and Lists of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT