Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write this Java program as simple as possible and with comments throughou

ID: 3724202 • Letter: P

Question



Please write this Java program as simple as possible and with comments throughout to explain what is happening. Thank you! Exercise 1: Design and implement a Java program (name it MinMaxAvg) that defines three methods as follows Method max (int x, int y, int z) determines and returns the maximum value of three integer values Method min (int x, int y, int z) determines and returns the minimum value of three integer values. Method average (int x, int y, int z) determines and returns the average of three integer values Test the methods with different input value read from the user (all input and output is handled by the main method). Invoke no methods from within any of the three methods listed above Design the main method of your program such that it allows the user to re-run the program with different inputs (i.e., use a loop structure). Document your code and organize and space the outputs properly. Use appropriate formatting techniques to organize the outputs. Sample output is You entered: -10 8 12 Max value: Min value: Average value: 3.33333333333 12 10

Explanation / Answer

MinMaxAvg.java

import java.util.Scanner;

public class MinMaxAvg {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

while(true){//loop to repeat the same task. enter n to quit from loop

System.out.print("Enter 3 numbers: ");

int a = scan.nextInt();//reading 3 numbers from console

int b = scan.nextInt();

int c = scan.nextInt();

System.out.println("You entered: "+a+" "+b+" "+c);

System.out.println("Max value: "+max(a,b,c));//calling max method to get max value

System.out.println("Min value: "+min(a,b,c));//calling min method to get min value

System.out.println("Average value: "+average(a,b,c));//caling average method to get average

System.out.print("Do you want to continue (y/n): " );

char ch = scan.next().charAt(0);

if(ch == 'n' || ch=='N'){//enter n to quit the loop

break;

}

}

}

//method to get max value

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

if(x > y && x>z){

return x;

}

else{

if(y>z){

return y;

}

else{

return z;

}

}

}//method to get min value

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

if(x < y && x<z){

return x;

}

else{

if(y<z){

return y;

}

else{

return z;

}

}

}

//method to get average value

public static double average(int x, int y, int z){

return (x+y+z)/(double)3;

}

}

Output:

Enter 3 numbers: -10 8 12
You entered: -10 8 12
Max value: 12
Min value: -10
Average value: 3.3333333333333335
Do you want to continue (y/n): n