Question

Write a method using JAVA called "maximum4" that returns the maximum of 4 decimal numbers. Use...

Write a method using JAVA called "maximum4" that returns the maximum of 4 decimal numbers. Use the "math.max" method to implement "maximum4". The user should enter the 4 values and the program determines the maximum and then display the result.

The steps for the Project could be the following:

  • Create the Maximum4 method that includes the math.max
  • Define and enter the variables
  • Apply the Maximum4 method you created to find the maximum of the 4 decimal numbers you entered and then display it.

Homework Answers

Answer #1

Code for Above Problem:

import java.util.Scanner;

public class MaximumDemo {

        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                // Asking user to enter decimal number1
                System.out.print("Enter decimal number 1: ");
                double number1 = sc.nextDouble();
                // Asking user to enter decimal number2
                System.out.print("Enter decimal number 2: ");
                double number2 = sc.nextDouble();
                // Asking user to enter decimal number3
                System.out.print("Enter decimal number 3: ");
                double number3 = sc.nextDouble();
                // Asking user to enter decimal number4
                System.out.print("Enter decimal number 4: ");
                double number4 = sc.nextDouble();

                // getting maximum of four decimal numbers by calling maximum4 method
                double max = maximum4(number1, number2, number3, number4);

                // Displaying maximum of four decimal numbers
                System.out.println("Maximum of four decimal numbers is: " + max);
                sc.close();
        }

        // method to return maximum of four decimal numbers
        public static double maximum4(double number1, double number2, double number3, double number4) {
                /*
                 * Single line answer Math.max(Math.max(Math.max(number1,
                 * number2),number3),number4)
                 */

                // get maximum of number1 and number2 and store in max
                double max = Math.max(number1, number2);
                // get maximum of max and number3 and store in max
                max = Math.max(max, number3);
                // get maximum of max and number4 and store in max
                max = Math.max(max, number4);
                // return max which is maximum of four decimal values
                return max;
        }
}

Sample Run Input/Output:

Enter decimal number 1: 15.3
Enter decimal number 2: 27.5
Enter decimal number 3: 82.2
Enter decimal number 4: 82.29
Maximum of four decimal numbers is: 82.29

Image Of Code:

Image Of Sample Run Input/Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns a 2D array of integers of size rows x cols where the value of element [row][col] is row + col. Write a short program to test your method.
A ________ is accurately represents large or very precise decimal numbers.    2. When a value...
A ________ is accurately represents large or very precise decimal numbers.    2. When a value is converted from one data type to another data type that can store either large numbers or numbers with greater precision it is called ______________ 3.  A procedure that returns a value is called a __________________ 4. A procedure that performs its task but does not return a value is called ______________ 5.  Local variables have a certain ____________ in the program whereas Global variables can...
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
Java Create a new Drive class. * Create a Menu class. * The menu class will...
Java Create a new Drive class. * Create a Menu class. * The menu class will use the previous 4 classes you created in GCD, LCM, FACTORIAL, DIGITS The Menu will display a menu that give you the option of selecting: 1) Greatest Common Denominator 2) Lowest Common Multiple 3) Factorial 4) Number of Digits in an Integer Enter 1,2,3 or 4: When the User enter the choice, then the correct function/method is called for the class and asks the...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...
in java pls Write a method that will receive 2 numbers as parameters and will return...
in java pls Write a method that will receive 2 numbers as parameters and will return a string containing the pattern based on those two numbers. Take into consideration that the numbers may not be in the right order. Note that the method will not print the pattern but return the string containing it instead. The main method (already coded) will be printing the string returned by the method. Remember that you can declare an empty string variable and concatenate...
I need the java code for a 4-function calculator app on android studio. Please make sure...
I need the java code for a 4-function calculator app on android studio. Please make sure all the requirements shown below are followed (such as the error portion and etc). The topic of this app is to simply create a 4 function calculator which calculates math expressions (add, subtract, multiply, and divide numbers). The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT