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...
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 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 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 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()...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT