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

Write a complete java program (name it Average) that defines a main method and 2

ID: 3679504 • Letter: W

Question

Write a complete java program (name it Average) that defines a main method and 2 other methods as follows: Method average(int x, y, int z) determines and returns the average value of the 3 variables (this should be a double). Method prepareMsg(int x, int y, int z, double ave) that returns a string of the following message The average value {x}, {y}, and {z} is {ave}. In the main method, show how you call these methods with valid values. You MUST ONLY print inside main and not in the other methods.

Explanation / Answer

This java program for calculate average value and print actual value

// This is test class Average
public class Average{
// define main function here
public static void main(String []args){
// define three variable here and assign valur in variable
int a= 1;
int b=5;
int c=9;
// chekc all avlue ineger and not if value not integer then show error message
if (a == (int)a && b == (int)b && c == (int)c)
{
// call average function here and assign value in avg variable
double avg = average(a,b,c);
// call message function here
String msg = prepareMsg(a, b, c, avg);
// print final message
System.out.println(msg);
}else{
System.out.println("Please enter valid intager value");
}
}
// this function use for count average value of all three variable
public static double average(int x, int y, int z){
// define all count varible here
int count=3;
// define sum varible
double sum =0.0;
// here count average of all avlue
sum = (x+y+z)/count;
// return avrage value
return sum;
}
// this function use for prepar final message and return
public static String prepareMsg(int x, int y, int z, double ave){
// define string msg varible msg
String msg;
// create final message here
msg = ("The average value " + x + ", " + y + ", and " + z + " is " + ave);
// return message
return msg;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote