Java please help asap Exercise 1: Design and implement a Java program (name it M
ID: 642954 • Letter: J
Question
Java please help asap 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 (in the main method) 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 escape characters to organize the outputs Sample output is You entered: 20 8 12 Max value: 20 Min value: 8 Average value: 13.33333333333Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class MinMaxAvg
{
int min(int x,int y,int z)
{
return (x < y ? (x < z ? x : z) : (y < z ? y : z));
}
int max(int x,int y,int z)
{
return (x > y ? (x > z ? x : z) : (y > z ? y : z));
}
double avg(int x,int y,int z)
{
return ((x+y+z)/3.0);
}
public static void main (String[] args) throws IOException
{
MinMaxAvg obj=new MinMaxAvg();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 0 to exit and any other digit to continue" );
int ch=Integer.parseInt(br.readLine());
while(ch!=0)
{
int x=Integer.parseInt(br.readLine());
int y=Integer.parseInt(br.readLine());
int z=Integer.parseInt(br.readLine());
System.out.println("You entered: "+x+" "+y+" "+z);
System.out.println("Max value: "+obj.max(x,y,z));
System.out.println("Min value: "+obj.min(x,y,z));
System.out.println("Average value: "+obj.avg(x,y,z));
System.out.println("Enter 0 to exit and any other digit to continue" );
ch=Integer.parseInt(br.readLine());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.