Question

In: Computer Science

(Java) Create a program using 3 methods. The methods must be public and static. Ask the...

(Java) Create a program using 3 methods. The methods must be public and static. Ask the user for 3 numbers, then call the methods from main to print max, min, and average.

The first method max (int x, int y, int z) returns the maximum value of 3 integer values.

The second method min (int X, int y, int z) returns the minimum value of 3 integer values.

And the third average (int x, int y, int z) returns the average of 3 integer values.

Sample Output: (bold = user input)

Enter # 1: 5

Enter # 2: 9

Enter # 3: 2

Min is 2

Max is 9

Average is 5.33333

Sample output 2

Enter # 1: 45

Enter # 2: 11

Enter # 3: -3

Min is -3

Max is 45

Average is 17.6667

Code Example:

int addTwoNumbers (int x, int y) {

int result = x + y;

return result;

Solutions

Expert Solution

Code:

import java.util.*;


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

int a, b, c;
int minimum, maximum;
float avg;

// Inputting the value of the 1st integer

System.out.print("Enter # 1: ");
a = sc.nextInt();

// Inputting the value of the 2nd integer

System.out.print("Enter # 2: ");
b = sc.nextInt();

// Inputting the value of the 3rd integer

System.out.print("Enter # 3: ");
c = sc.nextInt();
  
minimum = Test60.min(a, b, c); // Calling the method- min()
  
maximum = Test60.max(a, b, c); // Calling the method- max()
  
avg = Test60.average(a, b, c); // Calling the method- average()

// Displaying the maximum, minimum and the average of the 3 integers

System.out.println("Min is " + minimum);
System.out.println("Max is " + maximum);
System.out.printf("Average is %.5f", avg);
}

// Method- max() -> Returns the maximum of the 3 integers

public static int max(int x, int y, int z) {
if(x >= y && x >= z)
return x; // x is the largest
else if(y >= x && y >= z)
return y; // y is the largest
else
return z; // z is the largest
}

// Method- min() -> Returns the minimum of the 3 integers

public static int min(int x, int y, int z) {
if(x <= y && x <= z)
return x; // x is the smallest
else if(y <= x && y <= z)
return y; // y is the smallest
else
return z; // z is the smallest
}

// Method- average() -> Returns the average of the 3 integers

public static float average(int x, int y, int z) {
float avg = (x + y + z) / 3.0f;
  
return avg;
}
}


Related Solutions

Guidelines for the program: All methods listed below must be public and static. If your code...
Guidelines for the program: All methods listed below must be public and static. If your code is using a loop to modify or create a string, you need to use the StringBuilder class from the API. Keep the loops simple but also efficient. Remember that you want each loop to do only one "task" while also avoiding unnecessary traversals of the data. No additional methods are needed. However, you may write additional private helper methods, but you still need to...
The following Java program is NOT designed using class/object concept. public class demo_Program4_non_OOP_design { public static...
The following Java program is NOT designed using class/object concept. public class demo_Program4_non_OOP_design { public static void main(String[] args) { String bottle1_label="Milk"; float bottle1_volume=250; float bottle1_capacity=500; bottle1_volume=addVolume(bottle1_label, bottle1_volume,bottle1_capacity,200); System.out.println("bottle label: " + bottle1_label + ", volume: " + bottle1_volume + ", capacity: " +bottle1_capacity); String bottle2_label="Water"; float bottle2_volume=100; float bottle2_capacity=250; bottle2_volume=addVolume(bottle2_label, bottle2_volume,bottle2_capacity,500); System.out.println("bottle label: " + bottle2_label + ", volume: " + bottle2_volume + ", capacity: " +bottle2_capacity); } public static float addVolume(String label, float bottleVolume, float capacity, float addVolume)...
Write a java program that contains 3 overloaded static methods for calculating area of a circle,...
Write a java program that contains 3 overloaded static methods for calculating area of a circle, area of a cylinder and volume of a cylinder. Also create an output method which uses JOptionPaneto display instance field(s) and the result of the computing. Then code a driver class which will run and test calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output method. Thanks!!
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
in java. using the following template as a method, public static void shellSort(int[] array) { create...
in java. using the following template as a method, public static void shellSort(int[] array) { create a program that counts the number of comparisons and swaps of the sorting method does using int array1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // Best Case Test int array2[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // Worst Case Test int array3[] = {10, 4, 8, 2, 6, 1, 9, 3, 7, 5}; //...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable radius = -999 declare character choice create do while loop inside of do loop write: System.out.println(); System.out.println("*** CIRCLE CALCULATIONS ***"); System.out.println(); System.out.println("1. Enter the radius of the circle"); System.out.println("2. Display the area of the circle"); System.out.println("3. Display the circumference of the circle"); System.out.println("4. Quit"); System.out.println(); System.out.println("Enter a number from 1 - 4"); System.out.println(); Declare choice character and relate to scanner declare switch (choice) case...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your own threaded program using the threadExtend.java code and the threadRunnable.java code. A.) Focus the threadExtend.java code DETAILS TO NOTE: - It creates 4 instances of the same thread. This means that the thread code is actually running 4 separate times - The thread accepts 2 parameters, an INTEGER from 1 to 4, as well as an ID - Note the parameters are hard coded...
In Java. Create a class called FileSumWrapper with a method that has the signature public static...
In Java. Create a class called FileSumWrapper with a method that has the signature public static void handle(String filename, int lowerBound) Make this method call FileSum.read and make your method catch all the errors. FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound. FileSum : import java.io.File; import java.rmi.UnexpectedException; import java.util.Scanner; public class FileSum { public static int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT