Question: Write a Java program that uses 4 separate methods to print out specific output as outlined below. You will first need to include a constant

Write a Java program that uses 4 separate methods to print out specific output as outlined below. You will first need to include a constant double named PI.

The exact details for each method are as follows:

The first method needs perform all the arithmetic expressions on two variables. First, create the two int variables. You must add, subtract, multiply, divide, and find the modulus of the two variables. After each arithmetic expression, print a statement that shows what arithmetic expression you are using and the result. Keep in mind that integer division does not normally provide a decimal output. Use casting to provide a decimal output for division Example output: ********************** Method #1 ********************** Please enter 2 numbers (separated by a space) for input in Method #1: 12 156 1. Addition -- 12 + 156 = 168 2. Subtraction -- 12 156 = -144 3. Multiplication -- 12 * 156 = 1872 4. Division -- 12 / 156 = 0.076923 5. Modulus -- 156 % 17 = 3

The second method will perform all the same arithmetic expressions on two different variables. First, create two double variables and assign them any value, then perform all the arithmetic operations. Since you are working with floating-point numbers for this method, make sure that your output is formatted to only display 2 decimal spaces.

The third method will require you to use methods from the Math class to perform some calculations. First, create two double variables and collect user input using Scanner to give those 2 variables a value. Use the appropriate methods to do the following and print out the results:

Raise the first variable to the power of the second variable. For example, variable1^variable2

Find the floor value for your first variable

Find the ceiling value for your second variable

Find the absolute value for the first variable the second variable.

Find the square root of variable1 * variable2

Using your two variables, determine the area of the following shapes:

Square1: length and width = variable1

Square2: length and width = variable2

Rectangle: length = variable1 and width = variable2

Triangle: base = variable1 and height = variable2

Circle1: radius = variable1

Circle2: radius = variable2 Note: For v and vi, you will need to use PI. USE THE Math.PI CONSTANT! DO NOT USE YOUR OWN VARIABLE OR CONSTANT FOR PI.

The last method will require simple printing. First, create a double variable and an int variable. These variables do not need user input, instead you will give them values of your own choosing. The double variable must have an assignment in scientific notation. The int variable can be assigned any integer value. Use the format specifier for printf to print out your double variable in scientific notation, then with decimal spaces numbering from 1 through 5. For your int variable, use the format specifier to show preceding spaces from 0 through 5.

Your main method should look identical to the main method shown below:

public static void main(String args[]) { method1( ); method2( ); method3( ); method4( ); }

Each method should have the following method header, but you must change the method name (highlighted) accordingly.

public static void method1( ) {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!