Question

In: Computer Science

write a java program to evaluate the highest number input by user, cannot use math class,...

write a java program to evaluate the highest number input by user, cannot use math class, must use overloading . Must compute four computeHighNum methods. Here is what I have.

import java.util.Scanner;

public class Overload {
public static void main(String[] args){
Scanner input = new Scanner(System.in);


int number1 = input.nextInt();
int number2 = input.nextInt();
int number3 = input.nextInt();
  
//int maximum = maximum(number1, number2 );
System.out.printf("Highest integer is ");
  
  

// int number1 = input.nextInt();
// int number2 = input.nextInt();
// int number3= input.nextInt();

// int maximum = maximum(int number1, int number2, int number3);
// System.out.print("Highest number is %d%n",max());
  
  
  
  
//double number6 = input.nextDouble();
//double number7 = input.nextDouble();
//double number8 = input.nextDouble();
  
//double int = maximum( number1, number2, number3);
//System.out.println("The highest number is "+ maximum);
  

  
  
}
public static int computeHighNum(int x, int y, int z){
System.out.print("Enter 3 intergers, seperated by a space, on a single line: ");
int maximumValue = x;
  
if(y > maximumValue){
maximumValue = y;
}   
if(z > maximumValue){
maximumValue = z;
}
return maximumValue;

}
  
  
public static int computeHighNum(int x, int y){
System.out.printf("Enter 2 integers, seperated by a space, on a single line: \n");
int maximumValue = x;
if (y > maximumValue){
maximumValue = y;
}
return maximumValue;

}
public static double computeHighNum(double x, double y, double z){
System.out.println("Enter 3 doubles, separated by a space, on a single line: \n");
double maximumValue = x;
  
if(y > maximumValue){
maximumValue = y;
}   
if(z > maximumValue){
maximumValue = z;
}
return maximumValue;
}
public static double computeHighNum(double x, double y){
System.out.print("Enter 2 doubles, separated by a space, on a single line: \n");
double maximumValue = x;
if (y > maximumValue){
maximumValue = y;
}
return maximumValue;
}
}

Solutions

Expert Solution

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote

CODE:

import java.util.Scanner;

public class Overload {

   

    public static void main(String[] args){

       

        int number1, number2, number3, maximum;

        double num1, num2, num3, max;

       

        Scanner input = new Scanner(System.in);

   

        System.out.println("Enter 2 integers, seperated by a space, on a single line: ");

        number1 = input.nextInt();

        number2 = input.nextInt();

        maximum = computeHighNum(number1, number2);

        System.out.println("Highest integer is " + maximum);

       

        System.out.println("\nEnter 3 intergers, seperated by a space, on a single line: ");

        number1 = input.nextInt();

        number2 = input.nextInt();

        number3 = input.nextInt();

        maximum = computeHighNum(number1, number2, number3);

        System.out.println("Highest integer is " + maximum);

       

        System.out.println("\nEnter 2 doubles, separated by a space, on a single line: ");

        num1 = input.nextDouble();

        num2 = input.nextDouble();

        max = computeHighNum(num1, num2 );

        System.out.println("Highest double value is " + max);

       

        System.out.println("\nEnter 3 doubles, separated by a space, on a single line: ");

        num1 = input.nextDouble();

        num2 = input.nextDouble();

        num3 = input.nextDouble();

        max = computeHighNum(num1, num2, num3);

        System.out.println("Highest double value is " + max);

    }

   

    public static int computeHighNum(int x, int y){

        int maximumValue = x;

        if (y > maximumValue){

            maximumValue = y;

        }

        return maximumValue;

    }

   

    public static int computeHighNum(int x, int y, int z){

        int maximumValue = x;

        if(y > maximumValue){

            maximumValue = y;

        }  

        if(z > maximumValue){

            maximumValue = z;

        }

        return maximumValue;

    }

   

    public static double computeHighNum(double x, double y){

        double maximumValue = x;

        if (y > maximumValue){

            maximumValue = y;

        }

        return maximumValue;

    }

   

    public static double computeHighNum(double x, double y, double z){

        double maximumValue = x;

        if(y > maximumValue){

            maximumValue = y;

        }  

        if(z > maximumValue){

            maximumValue = z;

        }

        return maximumValue;

    }

}

OUTPUT:


Related Solutions

User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
JAVA Write a program that translates a user-input floating-point number between 0 and 4 into the...
JAVA Write a program that translates a user-input floating-point number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B–. Break ties in favor of the better grade; for example 2.85 should be a B. NOTE: Your implementation must include the definition/implementation and use/calling of the method numberGradeToLetterGrade that is passed a double numeric grade to its parameter variable, and returns the...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT